When using this plugin to import html files with an import statement in typescript, set to produce commonjs modules, I'm getting exports is not defined, in the browser, from the bundles created via jspm. The output looks something similar to:
System.register("app/components/component.html", [], function (_export, _context) {
"use strict";
return {
setters: [],
execute: function () {
Object.defineProperty(exports, "__esModule", { value: true });
exports.__useDefault = true;
exports.default = "<div>....</div>";
}
};
});
No problem when transpiling directly in the browser though.
I changed the plugin to
'use strict';
module.exports = {
translate: function (load) {
load.metadata.format = 'cjs';
var output =
'module.exports = function () {' +
' return module.exports["default"].apply(this, arguments);' +
'};'+
'Object.defineProperty(module.exports, "default", {value: '+JSON.stringify(load.source)+'});';
return output;
}
}
and nothing complains any more. The generated js through the bundle looks like:
System.registerDynamic("app/components/component.html", [], true, function ($__require, exports, module) {
var global = this || self,
GLOBAL = global;
module.exports = function () {
return module.exports["default"].apply(this, arguments);
};
Object.defineProperty(module.exports, "default", { value: "<div>...</div>" });
});
Also notice the difference between using registerDynamic vs register.
Any idea what's causing this?