Pug模板与HTML Webpack插件

4

我目前正在尝试使用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'],
        }),
    ],
};

有什么建议吗?
2个回答

4

我需要手动安装pug包本身。


1
你需要这样做。如果需要,你可以添加块。
new HtmlWebpackPlugin({
        filename: 'index.html',
        template: path.join(__dirname, './src/index.pug')
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接