webpack+react配置UglifyJsPlugin出现的问题
Posted 郑庙华
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webpack+react配置UglifyJsPlugin出现的问题相关的知识,希望对你有一定的参考价值。
webpack.config.js中的配置
const path=require(\'path\'); const webpack=require(\'webpack\'); const htmlWebpackPlugin=require(\'html-webpack-plugin\'); const CleanPlugin=require(\'clean-webpack-plugin\'); module.exports={ entry:\'./src/index.js\', output:{ path:path.resolve(__dirname, \'build\'), filename:\'[name]-[hash:5].js\' }, module:{ rules:[{ test: /\\.(jsx$|js)$/, exclude: /(node_modules|bower_components)/, include:/src/, use: { loader: \'babel-loader\', options: { presets: [\'env\',\'react\'] } } }] /*loaders: [ { test: /\\.css$/, loader: \'style-loader!css-loader\' }, { test: /\\.scss$/, loader: \'style!css!sass?sourceMap\'}, { test: /\\.styl$/, loader: \'style-loader!css-loader!stylus-loader\'}, { test: /\\.(png|jpg)$/, loader: \'url-loader?limit=8192\'}, { test: /\\.js$/, loader: "babel-loader", query: {presets: [\'es2015\',\'react\']}} loader: \'babel-loader?presets[]=es2015&presets[]=react\' ]*/ }, resolve: { extensions:[\'.js\',\'.json\'] }, plugins:[ new HtmlWebpackPlugin({ template:\'./src/index.html\' }), new CleanPlugin(\'build\'), new webpack.optimize.UglifyJsPlugin({ compress:{ warnings:false } }) ] }
npm run webpack后有告警
意思好像是说生产环境和开发环境室友区别的
plugins再加上一项就没事了
new webpack.DefinePlugin({ \'process.env\': {NODE_ENV: \'"production"\'} })
以上是关于webpack+react配置UglifyJsPlugin出现的问题的主要内容,如果未能解决你的问题,请参考以下文章
create-react-app 如何查看webpack配置
React/Webpack - 从 webpack 1 迁移到 4,配置对象无效
在 React 故事书自定义 webpack 配置中使用 webpack ProvidePlugin