我目前正在尝试让 Pug 模板与HTML Webpack Plugin一起运行。我按照他们的指示能够使用自定义模板引擎,例如 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'],
}),
],
};
有什么建议么?