[Webpack 2] Optimize React size and performance with Webpack production plugins
2023-09-14 08:59:19 时间
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基本配置项_webpack配置文件详解
- 入门webpack的最佳实践(基于webpack4.X 5.X) - source-map
- 「使用 webpack 5 从0到1搭建React+TypeScript 项目环境」2. 集成 css、less 与 sass
- 「使用 webpack 5 从0到1搭建React + TypeScript 项目环境」3. 资源模块
- React魔法堂:echarts-for-react源码略读
- Webpack最佳实践
- webpack配置优化,让你的构建速度飞起_2023-02-28
- create-react-app 设置webpack alias
- webpack css loader
- webpack+vue初始化项目
- 探索React框架中MySQL数据库的应用(react mssql)