我正在处理Webpack上的教程,但在添加HtmlWebpackPlugin并尝试再次运行Webpack之后,我收到以下错误:
Error: Cannot find module 'html-webpack-plugin'
at Function.Module._resolveFilename (module.js:489:15)
...
我已尝试在本地和全局安装插件,但我两次都收到错误。
//webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: "./app.js", // bundle entry point
output: {
path: path.resolve(__dirname, 'dist'), // output directory
filename: "[name].js" // name of generated bundle
},
plugins : [
new HtmlWebpackPlugin({
template: "index.html",
inject: "body"
})
]
};
//package.json
{
"name": "hyperlocalnola",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^2.30.1"
}
}
//app.js
var msg = require("./contents.js");
document.write(msg);
//contents.js
module.exports = "hello friend!";
对于可能非常简单的文本墙感到抱歉,但我无法找到导致此问题的原因。提前谢谢。