3

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

有什么建议么?

4

2 回答 2

3

我不得不手动安装pug包本身。

于 2017-06-15T12:59:30.083 回答
1

你必须这样做。如果需要,您可以添加块。

new HtmlWebpackPlugin({
        filename: 'index.html',
        template: path.join(__dirname, './src/index.pug')
    });
于 2019-01-17T07:33:20.173 回答