我目前正在尝试使用 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'],
}),
],
};
有什么建议?
最佳答案
我不得不手动安装 pug
包装本身。
关于webpack - 带有 HTML Webpack 插件的 Pug 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44565379/