-
Pug documentation https://github.com/pugjs/pug
-
Node-glob https://github.com/isaacs/node-glob
-
Este ejemplo fue probado con la versión "pug": "^2.0.0-beta2", ya que la versión "pug": "^0.1.0" no me permitía hacer uso de los include
var pug = require('pug');
var fs = require('fs');
var glob = require("glob");
var pattern = __dirname + "/frontend/pug/*.pug";
var src = __dirname + "/src/html/";
var filesInput = glob.sync(pattern);
// Compile the source code
filesInput.forEach(function(element, index) {
var path = element.split("/").pop();
var name = path.replace('pug', 'html');
var compiledFunction = pug.compileFile(element, {
filename : 'pug',
doctype: 'html',
pretty: true,
inlineRuntimeFunctions: true
});
var html = compiledFunction();
fs.writeFileSync(src.concat(name), html, 'utf-8');
});package.json
"scripts": {
"pug": "node ./pugDemo.js",
"watch": "pug -w ./frontend/pug/*.pug --pretty --out './src/html'"
},