-
Notifications
You must be signed in to change notification settings - Fork 9
/
hbs.js
24 lines (20 loc) · 970 Bytes
/
hbs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
import Handlebars from 'handlebars';
export function translate(load) {
let precompiled = Handlebars.precompile(load.source);
let handlebarsRuntimePath = System.normalizeSync('handlebars/handlebars.runtime.js', __moduleName);
// in builds we want to embed the canonical name for the handlebars runtime
if (System.getCanonicalName) {
handlebarsRuntimePath = System.getCanonicalName(handlebarsRuntimePath);
}
let output;
if (load.metadata.format === 'esm') {
output = `import Handlebars from '${handlebarsRuntimePath}'; \n export default Handlebars.template(${precompiled});`;
} else if (load.metadata.format === 'amd') {
output = `define(['${handlebarsRuntimePath}'], function (Handlebars) { return Handlebars.template(${precompiled}); });`;
} else {
output = `var Handlebars = require('${handlebarsRuntimePath}'); \n module.exports = Handlebars.template(${precompiled});`;
}
load.source = output;
return output;
}