作用
将抽离出来的runtime文件打包入html中,降低请求次数,在文件数量少得时候,优化加载
依赖
使用
webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InlineChunkHtmlPlugin = require('inline-chunk-html-plugin')
module.exports = {
//...
optimization: {
runtimeChunk: {
name: 'runtime',
},
},
plugins: [
new HtmlWebpackPlugin({
title: 'copyWebpackPlugin',
template: './public/index.html'
})
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime.*\.js/])
]
};