webpackhtml-webpack-pluginpug-loader

Pug templates with the HTML Webpack Plugin


I'm currently trying to get Pug templates running with the HTML Webpack Plugin. I followed their instruction to be able to use a custom template engine like Handlebars or in my case Pug. When I execute it, I'm getting this error:

ERROR in ./~/html-webpack-plugin/lib/loader.js!./src/index.pug
Module build failed: Error: Cannot find module 'pug'

My current config looks like this:

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'],
        }),
    ],
};

Any suggestions?


Solution

  • I had to manually install the pug package itself.