我正在尝试减少应用程序JS包的输出大小,并且查看这些是我到目前为止帮助我完成此任务的插件:
config.plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/),
new ExtractTextPlugin({ filename: "bundle.css" }),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
},
output: {
comments: false,
screw_ie8: true,
},
mangle: {
screw_ie8: true,
},
sourceMap: false,
minimize: true
}),
new LodashModuleReplacementPlugin({ 'collections': true }),
new DuplicatePackageCheckerPlugin()
];
我还将devtool
设置为undefined for production。
这是我的.babelrc
,我也在做一些优化:
{
"presets": [
["es2015", { "es2015": { "loose": true, "modules": false}}],
"react",
"stage-0",
],
"env": {
"development": {
"presets": ["react"]
},
"production": {
"plugins": [
["transform-react-remove-prop-types", {
"mode": "wrap",
}]
]
}
},
"plugins": ["lodash"]
}
我还能做其他事情吗?捆绑已经减少很多但仍然很大。