var Nunjucks = require('nunjucks');
var webpack = require('webpack');
// Set up templating.
var nunjucks = Nunjucks.configure(path.resolve(__dirname, 'src'), {noCache: true});
// Initial Nunjucks render.
var html = nunjucks.render('index.html', getContext());
fs.writeFileSync('index.html', html);
// For development, watch HTML for changes to compile Nunjucks.
// The production Express server will handle Nunjucks by itself.
if (process.env.NODE_ENV !== 'production') {
fs.watch('src', {recursive: true}, (eventType, filename) => {
if (filename.indexOf('.html') === -1) {
return;
}
console.log(`${filename} updated.`);
try {
fs.writeFileSync('index.html', nunjucks.render('index.html', getContext()));
} catch (e) {
console.error(e);
}
});
}
// ...
我的树:
index.html // Compiled HTML.
src/
index.html // Template/Nunjucks HTML.
templates/
somePartial.html
接下来包括:
{% include "./templates/somePartial.html" %}
<%= require('html-loader!./text.html') %>
吗?(参考链接:https://dev59.com/sFgQ5IYBdhLWcg3w0HEA) - Piotr Adam Milewski