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

DefinePlugin NODE_ENV not visible to babel-loader #2121

Closed
acthp opened this Issue Mar 1, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@acthp

acthp commented Mar 1, 2016

Using DefinePlugin to set process.env.NODE_ENV, it remains unset in babel-loader. It is available in other steps, as webpack is able to drop requires inside conditionals checking NODE_ENV.

babel-loader explicitly checks for process.env.NODE_ENV in order to pass it on to babel, but it is undefined.

@danpantry

This comment has been minimized.

Show comment
Hide comment
@danpantry

danpantry Mar 1, 2016

Could you provide your webpack.config.js?

danpantry commented Mar 1, 2016

Could you provide your webpack.config.js?

@dtothefp

This comment has been minimized.

Show comment
Hide comment
@dtothefp

dtothefp Mar 1, 2016

@acthp Babel loader uses the BABEL_ENV or NODE_ENV of the actual process that envies Babel. Therefore you need to set it via node and not Webpck unless I'm confused about your question

dtothefp commented Mar 1, 2016

@acthp Babel loader uses the BABEL_ENV or NODE_ENV of the actual process that envies Babel. Therefore you need to set it via node and not Webpck unless I'm confused about your question

@acthp

This comment has been minimized.

Show comment
Hide comment
@acthp

acthp Mar 1, 2016

Ah, that was it, thanks. In webpack.config.js If I do

process.env.NODE_ENV = '"production"'

in addition to configuring DefinePlugin, it is available to babel-loader as well as the other processors.

acthp commented Mar 1, 2016

Ah, that was it, thanks. In webpack.config.js If I do

process.env.NODE_ENV = '"production"'

in addition to configuring DefinePlugin, it is available to babel-loader as well as the other processors.

@acthp acthp closed this Mar 1, 2016

@imjared

This comment has been minimized.

Show comment
Hide comment
@imjared

imjared Apr 13, 2016

@acthp can you post your full webpack config or the parts affecting this issue? having similar problems and looking for something that works

imjared commented Apr 13, 2016

@acthp can you post your full webpack config or the parts affecting this issue? having similar problems and looking for something that works

@mzgoddard

This comment has been minimized.

Show comment
Hide comment
@mzgoddard

mzgoddard Apr 13, 2016

Contributor

@imjared DefinePlugin transforms code parsed by webpack after all loaders. It doesn't do anything to the global environment. You can either literally set NODE_ENV in your webpack.config.js file as a single statement or set the environment when running webpack.

// webpack.config.js
process.env.NODE_ENV = 'production';

module.exports = {
  entry: './index.js',
  // ...
  plugins: [
    new DefinePlugin({
      'process.env.NODE_ENV': '"production"',
    }),
  ],
};

OR

NODE_ENV=production webpack --config=webpack.config.js

If there is code that is going into the webpack'd source that tests process.env.NODE_ENV, you'll want both DefinePlugin and the actual shell environment variable to be set.

Contributor

mzgoddard commented Apr 13, 2016

@imjared DefinePlugin transforms code parsed by webpack after all loaders. It doesn't do anything to the global environment. You can either literally set NODE_ENV in your webpack.config.js file as a single statement or set the environment when running webpack.

// webpack.config.js
process.env.NODE_ENV = 'production';

module.exports = {
  entry: './index.js',
  // ...
  plugins: [
    new DefinePlugin({
      'process.env.NODE_ENV': '"production"',
    }),
  ],
};

OR

NODE_ENV=production webpack --config=webpack.config.js

If there is code that is going into the webpack'd source that tests process.env.NODE_ENV, you'll want both DefinePlugin and the actual shell environment variable to be set.

@joeLloyd

This comment has been minimized.

Show comment
Hide comment
@joeLloyd

joeLloyd Jan 16, 2017

what about using dotenv? with it always fail if you use that?

joeLloyd commented Jan 16, 2017

what about using dotenv? with it always fail if you use that?

@mlg87 mlg87 referenced this issue Dec 15, 2017

Closed

Prevent MUI from optimizing class names in prod #8996

1 of 1 task complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment