包.json
{
"name": "test2",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^4.5.0",
"webpack": "^5.1.3",
"webpack-cli": "^4.1.0"
}
}
Run Code Online (Sandbox Code Playgroud)
webpack.config.js
const {resolve} = require('path');
const {HtmlWebpackPlugin} = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'built.js',
path: resolve(__dirname, 'build')
},
plugins: [
new HtmlWebpackPlugin({template: './src/webpack.html'})
],
mode: 'development'
};
Run Code Online (Sandbox Code Playgroud)
我的错误:
[webpack-cli] TypeError: HtmlWebpackPlugin is not a constructor
at Object.<anonymous> (D:\webpack …
Run Code Online (Sandbox Code Playgroud)