webpack - 带有 HTML Webpack 插件的 Pug 模板

标签 webpack html-webpack-plugin pug-loader

我目前正在尝试使用 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/

相关文章:

javascript - 如何在 webpack 中加载 Pug 模板而不编译为 HTML?

javascript - React Suspense 在错误的目录中查找 block

gulp - 使用 Webpack 连接和缩小 CSS 文件而不需要它们

webpack - 如何创建没有 PWA 功能的 CRA 项目?

javascript - ES6 语法错误 const

performance - Html-Webpack-Plugin 在多个 pug 文件上非常慢

webpack - 如何告诉webpack仅对特​​定文件使用插件或加载器?

webpack - HtmlWebpackPlugin 包含的包文件的顺序

webpack - html-webpack-plugin:如何将标题等参数注入(inject)模板

webpack - 如何使用 webpack 从 pug 模板输出 html 文件?