gruntjs / grunt-contrib-pug

Compile Pug templates.
http://gruntjs.com/
MIT License
328 stars 77 forks source link

Combined templates file references incorrect runtime #175

Open andrewminer opened 7 years ago

andrewminer commented 7 years ago

If you use this plugin to create a single downloadable template file from many different pug files, it adds the following line to the top of your template file:

var pug = pug || require('pug/lib/runtime');

That file no longer exists in the main pug package, and when combined with #169, that pretty much means you're screwed since your template file will attempt to reference a non-existent file.

This should be changed to require pug-runtime instead.

XhmikosR commented 7 years ago

When did this change? Tests are passing so we need more info.

andrewminer commented 7 years ago

I'm not sure when it changed, but I set up a project using grunt-contrib-pug within the past week, and found that this was the case using the latest version of pug from NPM.

Here's the (CoffeeScript) config I used which produced the problem:

        pug:
            pages:
            templates:
                options:
                    client: true
                    compileDebug: false
                    node: true
                    pretty: false
                    inlineRuntimeFunctions: false
                    processName: (f)->
                        f = f.replace DIR_SRC_VIEWS, ""
                        f = f.replace /^\/[^\/]+\/([^.]+)\.pug$/ , "$1"
                        return f
                files:
                    "#{DIR_SRC_VIEWS}/templates.js": ["#{DIR_SRC_VIEWS}/**/*.pug"]

Running this shell script on the output template file makes everything work as expected:

sed -i '' 's/pug\/lib\/runtime/pug-runtime/' "$TEMPLATE_FILE"