pugjs / pug-loader

Pug loader module for Webpack
MIT License
425 stars 119 forks source link

Include breaks inside a template with HtmlWebpackPlugin #69

Open Velenir opened 8 years ago

Velenir commented 8 years ago

When including a .pug file as a template in HtmlWebpackPlugin:

plugins: [
        new HtmlWebpackPlugin({
            template: '!!pug!./app/index.pug'
        })
    ]
//- index.pug
doctype html
html
    head
        title Page Title

    body

        h1 Pug Template
        include partial.pug
//- partial.pug
h2 This was included from partial.pug

Executing webpack-dev-server throws

ERROR in ./app/partial.pug Module parse failed: /path/to/pug-loader--bug/app/partial.pug Unexpected token (1:3) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (1:3)

But if I either add a mixin to partial.pug:

h2 This was included from partial.pug
mixin m
    p

Or add a loader to webpack.config.js:

module: {
        loaders: [
            {
                test: /\.pug$/,
                loader: 'pug'
            }
        ]
    }

everything works.

Simply requiring index.pug in a javascript file works properly, mixin or no mixin. To summarize:

--- Loader Mixin
Breaks X X
Works V X
Works X V
Works V V

How can mere presence of a mixin make or break include? I have no idea. Test repo

MikaAK commented 7 years ago

Found a workaround. Use require in your template != require('apply!pug!./path/to/file.pug')