No indroduction here, starting.
- Use the right environment variable
new webpack.DefinePlugin({âprocess.envâ: {âNODE_ENVâ: âproductionâ}})
2. Use production parameter
webpack -p
3. Advanced uglification
new UglifyJSPlugin({// options})
4. Optimizing dependencies import
Instead of import the full dependency:
import _ from âlodashâ;
Just import what you really need:
import _ from âlodash/coreâ;
5. Use Bundle Analyzer to figure out what increases the size
e.g. Most of the time we should ignore the moment locale files
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
6. Extract vendors out of your bundle
module.exports = {âŚ,entry: {app: â./src/index.jsâ,vendor: [âreactâ, âmomentâ, âlodash/coreâ]},âŚ,plugins: [âŚ,new webpack.optimize.CommonsChunkPlugin({name: âvendorâ})]};
7. Extract vendors out of your bundle
module.exports = {âŚ,module: {rules: [âŚ,// css{test: /\.css$/,use: ExtractTextPlugin.extract({fallback: âstyle-loaderâ,use: [âcss-loaderâ]})}]},plugins: [âŚ,new ExtractTextPlugin(âstyle.cssâ),]};
8. Code split by routes
Result per step on one of my project
See ya.