码迷,mamicode.com
首页 > Web开发 > 详细

[Webpack 2] Optimize React size and performance with Webpack production plugins

时间:2016-06-25 06:09:06      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

You can fine tune several webpack plugins to make your bundle as small as it can be for your specific application. However there are a few things you can do for pretty much every application to make it smaller and run faster. In this lesson we’ll combine several webpack plugins to optimize things for a React application (this is also applicable for non-React applications as well).

 

First we need to modify the prod scripts from:

"build:prod": "webpack --env.prod -p",

to:

"build:prod": "webpack --env.prod",

 

Help methods:

    plugins: removeEmpty([
      // doesn‘t save anything in this small app. npm@3 mostly takes care of this
      ifProd(new webpack.optimize.DedupePlugin()),
      // saves a couple of kBs
      ifProd(new webpack.LoaderOptionsPlugin({  //Loader plugin only works in webpack 2
        minimize: true,
        debug: false,
        quiet: true,
      })),
      // saves 65 kB with Uglify!! Saves 38 kB without
      ifProd(new webpack.DefinePlugin({
        process.env: {
          NODE_ENV: "production",
        },
      })),
      // saves 711 kB!!
      ifProd(new webpack.optimize.UglifyJsPlugin({
        compress: {
          screw_ie8: true, // eslint-disable-line
          warnings: false,
        },
      })),
    ])

 

[Webpack 2] Optimize React size and performance with Webpack production plugins

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5615677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!