compile: what's the recommendation now that compile option is gone?
warpdesign opened this issue · 1 comments
The compile option was removed in v3.
What's the best way to compile js/less files?
I used to have something like this in my docma-template.json file:
{
compile: {
"js/app.js": "js/app.min.js"
}
Should I add some build scripts into mytemplate/package.json and call them in the prebuild()
callback?
Recommendation is to use previously compiled files so the end-user builds their docs faster. So in your case, this means including the final minified JS file rather than integrating an uglify operation into the build process.
Workaround is to use preBuild()
option. You don't call preBuild()
yourself. It will be part of the docs-build process run by Docma core. In other words, preBuild()
is a way to tell docma to run some operation every time the user builds their documentation.
For helpers you can use utils.js.minify()
or utils.js.minifyFile()
methods. These utils are not officially documented but they will not go anywhere since docma uses them for its own files. Or you can use your own functions/helpers...
module.exports = (template, modules) => {
// Docma passes the following modules to this template module for your convenience.
// _, Promise, fs, dust, HtmlParser, utils
const { Promise, utils, fs } = modules;
// Set template main HTML file (default is "index.html")
template.mainHTML = 'main.html';
// Template default options.
template.defaultOptions = {
title: 'Docs',
header: true
// other options specific to your templated web app
};
// ignore files relative to /template directory. other files in the root of the module directory are already ignored.
template.ignore = [];
// optionally run some code before the build has started.
template.preBuild(async () => {
// minify your JS files and write them out to destination...
const minifed = await utils.js.minifyFile('path/to/original.js');
return fs.outputFile('path/to/minified.js', minified.code); // returning a promise
});
};