作用

将抽离出来的runtime文件打包入html中,降低请求次数,在文件数量少得时候,优化加载

依赖

需要安装inline-chunk-html-plugin

使用

webpack.config.js

  1. const HtmlWebpackPlugin = require('html-webpack-plugin')
  2. const InlineChunkHtmlPlugin = require('inline-chunk-html-plugin')
  3. module.exports = {
  4. //...
  5. optimization: {
  6. runtimeChunk: {
  7. name: 'runtime',
  8. },
  9. },
  10. plugins: [
  11. new HtmlWebpackPlugin({
  12. title: 'copyWebpackPlugin',
  13. template: './public/index.html'
  14. })
  15. new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime.*\.js/])
  16. ]
  17. };