今天嘗試將就專案的webpack從v3升到v4,結果webpack-dev-middleware,一開啟一直跳出此錯誤訊息:
You are currently using minified code outside of NODE_ENV === ‘production’. This means that you are running a slower development build of Redux. You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) to ensure you have the correct code for your production build.
找了很多文章,都是說在webpack.config.js加上此句,
1 2 3 4 5 |
new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('development') } }) |
或是將react-router從v3升級v4,但我原本就使用4.0.0了,但還是嘗試升級看看,
反而我從4.0.0升到4.0.5又出現其他錯誤訊息,只好將回4.0.0版本,
不管怎麼在設定檔案上做NODE_ENV的參數,都會報錯,
後來看到此command設定:
1 2 3 |
"dev": "webpack --mode development", "build": "webpack --mode production" |
好像可以解決我的問題,但我又發現我是使用webpack-dev-middleware,
並沒有地方可以設定command,幸好在原本的webpack.config.js可以加上此參數
mode:”development”
1 2 3 4 5 6 7 8 9 |
module.exports = { mode:"development", //入口文件 entry:{ 'webpack-hot-middleware/client', path.resolve(__dirname, 'react') }, ... ... |
設定完後,重新啟動start:dev,就沒有在跑出此錯誤訊息了!
mode此參數為v4所新增的。
Reference
https://blog.csdn.net/jiang7701037/article/details/80682662