Webpack插件: DllPlugin: 用于打包出一个个单独的动态链接库文件 DllReferencePlugin: 用于在主要的配置文件中引入DllPlugin插件打包好的动态链接库
const path = require(‘path’); const DllPlugin = require(‘webpack/lib/DllPlugin’);
module.exportsc = { entry: { polyfill: [ ‘core-js/fn/obejct/assign’, ‘core-js/fn/promise’, ‘whatwg-fetch’ ] }, output: { path: path.join(__dirname, ‘dist’), filename: ‘[name].dll.js’, library: ‘dll[name]’ }, plugins: [ new DllPlugin({ name: ‘dll[name]’, path: path.join(__dirname, ‘dis’, ‘[name].mainfest.json’) }) ] }
plugin: [ new DllReferencePlugin({ manifest: require(’./dist/polyfill.mainfest.json’) }) ], devtool: ‘sourse-map’
将部分任务分解到多个进程中去并行处理 module: { rules:[{ test: /.js$/, //use: [‘babel-loader?cacheDirectory’],
use: ['happypack/loader?id=label'], include: path.resolve(__dirname, 'src'), exclude: path.resolve(__dirname, 'node_modules') }, { test: /\.css$/, use: [ MiniCssExtractPlugin.loader, 'happyhack/loader?id=css' ] }] }, plugin: [ new DllReferencePlugin({ manifest: require('./dist/polyfill.mainfest.json') }), new HappyPack({ id: 'babel', loader:['babel-loader?cacheDirectory'], threadPool: happyThreadPool }), new HappyPack({ id: 'css', loader:['css-loader'], threadPool: happyThreadPool }) ], devtool: 'sourse-map'new ParallelUglifyPlugin({ uglifyJS: { output: { beautify: false, //紧凑输出 comments: false //删除注释 } } })
1.自动刷新原理 (1)借助浏览器提供的接口去刷新 (2)想要开发的网页注入代理客户端代码,通过代理客户端刷新这个页面 (3)将要开发的网页装进iframe,通过刷新iframe看到最新效果
Web-dev-server默认采用的是第二种
Webpack-dev-server --inline false 采用第三种,不用给每个输出的chunk都注入代理客户端代码
process.env.NODE_ENV
publicPath: ‘’ Web-webpack-plugin
关闭babel自动转换功能,再通过压缩UglifyJS处理或者直接运行的时候带上 --optimize-minimize参数 { “presets”: [ [ “env”, { “modules”: false } ] ] }
new HotModuleReplacementPluCommonChunkPlugbingin(), new CommonChunkPlugbin({ chunks: [‘a’, ‘b’], name: ‘common’ })
在编译阶段预执行源码得到结果
new CommonChunkPlugbin({ chunks: [‘a’, ‘b’], name: ‘common’ }), new PrepackWebpackPlugin()
打出来的文件更小,运行的更快
new PrepackWebpackPlugin(), new ModuleConcatenationPlugin()
