-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Description
package.json:
{
"name": "test",
"version": "0.0.1",
"dependencies": {},
"devDependencies": {
"react": "0.12.2",
"webpack": "1.7.2"
}
}main.js:
var React = require('react')
console.log(process.env.NODE_ENV)webpack.config.js:
var webpack = require('webpack')
module.exports = {
entry: {
app: './main'
},
output: {
path: '_dist',
filename: 'out.js'
},
resolve: {
extensions: ['', '.js', '.json']
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"production"'
}
})
]
}Place all these files into the same directory and then run:
npm install
rm -rf _dist && ./node_modules/.bin/webpackThen inspect _dist/out.js. You will see that process.env.NODE_ENV has been successfully injeted to main.js module (line 47):
var React = __webpack_require__(1)
console.log(("production"))But all entries of process.env.NODE_ENV inside React modules remain intact, e.g. line 314:
("production" !== process.env.NODE_ENV ? warning(
standardName == null,
'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?'
) : null);You can verify this by searching for ("production") and process.env.NODE_ENV. Changing definition to a flat one doesn't help:
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
})
]However, when I add UglifyJSPlugin, injection starts working as intended: UglifyJS prints a lot of Condition always false messages, and there are no occurrences of NODE_ENV inside the minified out.js.
bishopZ, jaydp17, arunshejul, annyhe, zhangchen2397 and 26 morefkazemi5236diem1, danoc, ixax, acupofspirt, superKalo and 6 more
Metadata
Metadata
Assignees
Labels
No labels