Simon Knittel
Simon Knittel

Reputation: 1851

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?

Upvotes: 4

Views: 3812

Answers (2)

Mirza Andriamanamisoa
Mirza Andriamanamisoa

Reputation: 421

You have to do it like this. You can add chunks if you want.

new HtmlWebpackPlugin({
        filename: 'index.html',
        template: path.join(__dirname, './src/index.pug')
    });

Upvotes: 1

Simon Knittel
Simon Knittel

Reputation: 1851

I had to manually install the pug package itself.

Upvotes: 4

Related Questions