caiogondim / webpack-conditional-loader

C conditionals directive for JavaScript
https://npm.im/webpack-conditional-loader
MIT License
110 stars 25 forks source link

Doesn't work #5

Open valentinvoilean opened 6 years ago

valentinvoilean commented 6 years ago

This is my webpack configuration:

rules: [
      {
        test: /\.jsx?$/,
        exclude: [/node_modules/],
        loader: ['babel-loader', 'webpack-conditional-loader']
      }
],

plugins: [
new webpack.EnvironmentPlugin({
      NODE_ENV: 'production',
      BROWSER: true
    }),
]

Then, in my file I use this:

// #if process.env.NODE_ENV !== 'production'
import moment from 'moment';
// #endif

The moment library is still imported.

It works only if I do:

// #if process.env.NODE_ENV === 'anything_other_value'
import moment from 'moment';
// #endif

This means, the process.env.NODE_ENV is undefined.

I'm using: "webpack": "^3.9.1", "webpack-conditional-loader": "^1.0.11",

statefull commented 6 years ago

Just define NODE_ENV as environment variable before call webpack