I'm having real issues injecting the node_env var into my code through Webpack's definePlugin and after reading numerous posts nothing seems to work. I have a feeling I'm missing something...
So my production webpack config is -
// Config
import path from 'path';
import webpack from 'webpack';
import config from './config';
/**
* Webpack config for compiling the
* React/Redux/ES6 scripts.
*
* ENV = production
*
* @type {Object}
*/
module.exports = {
entry: path.resolve(__dirname, '../', config.assets.scripts.src_dir, config.assets.scripts.entry),
devtool: false,
output: {
path: path.resolve(__dirname, config.assets.scripts.dist_dir),
filename: config.assets.scripts.dist_min
},
module: {
loaders: [
{
test: /.js?$/,
loader: 'babel-loader?presets[]=react,presets[]=es2015,presets[]=stage-0',
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({})
]
};
I've tried setting alias's for react, react-dom and react-redux with absolutely no avail, React still warns me i'm using a minified version outside of node_env=production (Also redux still throws me this error).
FYI, i'm using webpack version 2.2.1.
Is it something to do with the babel-loader conflicting in some way? If anyone can point me in the right direction that would be great.
Try changing your DefinePlugin
for NODE_ENV
to this one -
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV' : JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
minimize : true,
compress : {
warnings : false
}
})
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With