Source map v3 generation for Pug v2.x (aka Jade).
Designed as a node.js helper for Brunch and Rollup plugins in my current projects, I hope it will be useful to you.
npm install gen-pug-source-map --save
genPugSourceMap( compiledFileName, compiledTemplate [, options] ) -> { data, map }
Mustly, compiledFileName
will be the name of the root .pug template (the generator adds .js
to this) and options
will contain basedir
with the same value that you pass to the compiler.
Compile the .pug with compileDebug:true
and pass the filename, generated code, and options to the source map generator.
It returns a plain JavaScript object with {data, map}
properties, where data
is the generated code and map
is an object containing a raw source map.
By default, the generator uses file names relative to the current directory, removes the inlined templates and lines with debugging information, and inserts the templates in the source map (useful for remote debugging), but you can change this behavior with this options:
basedir
- Define the root directory of the source files with relative names.keepDebugLines
- Keep the lines with debugging information in the generated code.excludeContent
- Does not include the original source(s) in the resulting source map.
If basedir
is missing or empty, it defaults to the current directory.
Inlined templates and debugging information are used by the pug runtime to display errors, something useful in development mode. For production, better use the default keepDebugLines:false
as the size of the generated code is about 4x with debugging info.
const genPugSourceMap = require('gen-pug-source-map')
const pug = require('pug')
function compile (filename, source, options) {
options.filename = filename // REQUIRED
options.compileDebug = true // REQUIRED
options.inlineRuntimeFunctions = false // recommended, use the global `pug` runtime
const output = pug.compileClient(source, options)
const result = genPugSourceMap(filename, output.body, { basedir: options.basedir })
return result // {data, map}
}
Note:
The signature of v0.1.0 (filename, source, compiled [, options])
is supported, but the source
parameter is deprecated and will be removed in v0.2.x
The generated map does not allow to set breakpoint on insert
directives nor in the first line of inserted files.
See changes in the CHANGELOG.