HtmlWebpackInlineSourcePlugin TypeError:无法读取未定义的属性“getHooks”

Sam*_*mmy 5 webpack webpack-4

尝试构建以下 webpack 文件时,标题中出现错误:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');

module.exports = {
  module: {
    rules: [{
        test: /\.js$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /\.(scss)$/,
        use: [{
          loader: 'style-loader', // inject CSS to page
        }, {
          loader: 'css-loader', // translates CSS into CommonJS modules
        }, {
          loader: 'postcss-loader', // Run post css actions
          options: {
            plugins: function() { // post css plugins, can be exported to postcss.config.js
              return [
                require('precss'),
                require('autoprefixer')
              ];
            }
          }
        }, {
          loader: 'sass-loader' // compiles Sass to CSS
        }]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/index.html',
      inlineSource: '.(js|css)$'
    }),
    new HtmlWebpackInlineSourcePlugin()
  ],

  entry: './src/index.js',

  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },

  mode: 'development'
};
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

FWIW 我正在使用纱线工作区。

Olu*_*ule 4

HtmlWebpackInlineSourcePlugin正在编译期间调用getHooks方法HtmlWebpackPlugin

此方法仅在版本4 及更高版本HtmlWebpackPlugin中可用。

这就是文档建议使用此版本及更高版本的原因。

您可以通过安装html-webpack-plugin@next来获取此版本