Skip to content

Commit

Permalink
Merge pull request #15 from davis/get-canonical-name
Browse files Browse the repository at this point in the history
make fixes for bundling
  • Loading branch information
davis authored Sep 12, 2016
2 parents a050d8f + 6c453e1 commit 439c31a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions hbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ 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 'handlebars/handlebars.runtime.js'; \n export default Handlebars.template(${precompiled});`;
output = `import {Handlebars} from '${handlebarsRuntimePath}'; \n export default Handlebars.template(${precompiled});`;
} else if (load.metadata.format === 'amd') {
output = `define(['handlebars/handlebars.runtime.js'], function(Handlebars) { return Handlebars.template(${precompiled}); });`;
output = `define(['${handlebarsRuntimePath}'], function (Handlebars) { return Handlebars.template(${precompiled}); });`;
} else {
output = `var Handlebars=require('handlebars/handlebars.runtime.js'); \n module.exports = Handlebars.template(${precompiled});`;
output = `var Handlebars = require('${handlebarsRuntimePath}'); \n module.exports = Handlebars.template(${precompiled});`;
}
load.source = output;
return output;
Expand Down

0 comments on commit 439c31a

Please sign in to comment.