我目前正在尝试使用HTML Webpack Plugin运行Pug模板。我按照他们的指示,能够使用像Handlebars这样的自定义模板引擎,或者在我的案例中使用Pug。当我执行它时,我收到了这个错误:
ERROR in ./~/html-webpack-plugin/lib/loader.js!./src/index.pug
Module build failed: Error: Cannot find module 'pug'
我当前的配置如下所示:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: {
global: './src/assets/scripts/global.js',
index: './src/assets/scripts/index.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist/js'),
publicPath: '/assets/js/',
},
module: {
rules: [
{test: /\.pug$/, use: 'pug-loader'},
],
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.pug',
filename: 'index.html',
chunks: ['global', 'index'],
}),
],
};
有什么建议吗?
答案 0 :(得分:3)
我不得不手动安装pug
软件包。
答案 1 :(得分:1)
您必须这样做。您可以根据需要添加块。
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(__dirname, './src/index.pug')
});