diff --git a/public/react/config/webpack.config.dev.js b/public/react/config/webpack.config.dev.js index 2fc1bbe64..48e4f7f52 100644 --- a/public/react/config/webpack.config.dev.js +++ b/public/react/config/webpack.config.dev.js @@ -9,6 +9,7 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); const eslintFormatter = require('react-dev-utils/eslintFormatter'); const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); +const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin'); // const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); const getClientEnvironment = require('./env'); const paths = require('./paths'); @@ -249,6 +250,46 @@ module.exports = { // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack // You can remove this if you don't use Moment.js: new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), + new ParallelUglifyPlugin({ + // 传递给 UglifyJS的参数如下: + uglifyJS: { + output: { + /* + 是否输出可读性较强的代码,即会保留空格和制表符,默认为输出,为了达到更好的压缩效果, + 可以设置为false + */ + beautify: false, + /* + 是否保留代码中的注释,默认为保留,为了达到更好的压缩效果,可以设置为false + */ + comments: false + }, + compress: { + /* + 是否在UglifyJS删除没有用到的代码时输出警告信息,默认为输出,可以设置为false关闭这些作用 + 不大的警告 + */ + warnings: false, + + /* + 是否删除代码中所有的console语句,默认为不删除,开启后,会删除所有的console语句 + */ + drop_console: true, + + /* + 是否内嵌虽然已经定义了,但是只用到一次的变量,比如将 var x = 1; y = x, 转换成 y = 5, 默认为不 + 转换,为了达到更好的压缩效果,可以设置为false + */ + collapse_vars: true, + + /* + 是否提取出现了多次但是没有定义成变量去引用的静态值,比如将 x = 'xxx'; y = 'xxx' 转换成 + var a = 'xxxx'; x = a; y = a; 默认为不转换,为了达到更好的压缩效果,可以设置为false + */ + reduce_vars: true + } + } + }), ], // Some libraries import Node modules but don't use them in the browser. // Tell Webpack to provide empty mocks for them so importing them works. diff --git a/public/react/config/webpack.config.prod.js b/public/react/config/webpack.config.prod.js index abeb58db9..e70e04fac 100644 --- a/public/react/config/webpack.config.prod.js +++ b/public/react/config/webpack.config.prod.js @@ -10,6 +10,8 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); const eslintFormatter = require('react-dev-utils/eslintFormatter'); const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); +const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin'); + const paths = require('./paths'); const getClientEnvironment = require('./env'); @@ -270,25 +272,39 @@ module.exports = { // Otherwise React will be compiled in the very slow development mode. new webpack.DefinePlugin(env.stringified), // Minify the code. - new webpack.optimize.UglifyJsPlugin({ - compress: { + // new webpack.optimize.UglifyJsPlugin({ + // compress: { + // warnings: false, + // // Disabled because of an issue with Uglify breaking seemingly valid code: + // // https://github.com/facebookincubator/create-react-app/issues/2376 + // // Pending further investigation: + // // https://github.com/mishoo/UglifyJS2/issues/2011 + // comparisons: false, + // }, + // mangle: { + // safari10: true, + // }, + // output: { + // comments: false, + // // Turned on because emoji and regex is not minified properly using default + // // https://github.com/facebookincubator/create-react-app/issues/2488 + // ascii_only: true, + // }, + // sourceMap: shouldUseSourceMap, + // }), + + new ParallelUglifyPlugin({ + cacheDir: '.cache/', + uglifyJS:{ + output: { + comments: false + }, warnings: false, - // Disabled because of an issue with Uglify breaking seemingly valid code: - // https://github.com/facebookincubator/create-react-app/issues/2376 - // Pending further investigation: - // https://github.com/mishoo/UglifyJS2/issues/2011 - comparisons: false, - }, - mangle: { - safari10: true, - }, - output: { - comments: false, - // Turned on because emoji and regex is not minified properly using default - // https://github.com/facebookincubator/create-react-app/issues/2488 - ascii_only: true, - }, - sourceMap: shouldUseSourceMap, + compress: { + drop_debugger: true, + drop_console: true + } + } }), // Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`. new ExtractTextPlugin({