Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README switch-case example does not work with webpack env object #177

Closed
cmavelis opened this issue Mar 19, 2021 · 3 comments
Closed

README switch-case example does not work with webpack env object #177

cmavelis opened this issue Mar 19, 2021 · 3 comments

Comments

@cmavelis
Copy link

Using switch(env) when env is an object and the cases are strings will always go to the default. It seems either the example is out of date or it should just be an if block.

module.exports = env => {
  switch(env) {
    case 'development':
      return merge(commonConfig, developmentConfig);
    case 'production':
      return merge(commonConfig, productionConfig);
    default:
      throw new Error('No matching configuration was found!');
  }
}
@cmavelis
Copy link
Author

cmavelis commented Mar 19, 2021

This is what I used instead:

module.exports = env => {
    if (env['development']) {
        return merge(commonConfig, devConfig);
    } else if (env['production']) {
        return merge(commonConfig, prodConfig);
    } else {
        throw new Error('Please specify webpack "--env development" or "--env production"');
    }
};

@bebraw
Copy link
Member

bebraw commented Mar 19, 2021 via email

@bebraw
Copy link
Member

bebraw commented Jun 7, 2021

This was solved in #180.

@bebraw bebraw closed this as completed Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants