Skip to content

Commit

Permalink
feat(build): add support for external modules
Browse files Browse the repository at this point in the history
Now you can inject stubs for modules that are only available at runtime and avoid `File not found or not accessible` console logs via `aurelia.json` or cli task.

Closes #802
  • Loading branch information
DarkHarlock committed Feb 3, 2018
1 parent ceb7860 commit fc5f197
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/build/bundled-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ exports.BundledSource = class {
let bundler = this.bundler;
let loaderConfig = bundler.loaderConfig;
let loaderPlugins = bundler.loaderOptions.plugins;
let externalModules = bundler.loaderOptions.externalModules || {};
let rootDir = process.cwd();
let moduleId = this.moduleId || (this.moduleId = this.calculateModuleId(rootDir, loaderConfig));
let that = this;
Expand Down Expand Up @@ -87,6 +88,13 @@ exports.BundledSource = class {
return true;
},
fileRead: function(defaultRead, id, filePath) {
if (id in externalModules) {
let externalContentResult = makeModuleContent(externalModules[id], defaultRead, id, filePath);
if (externalContentResult) {
return externalContentResult;
}
}

let location = calculateFileName(filePath);
let found = bundler.getItemByPath(location);

Expand Down Expand Up @@ -209,3 +217,13 @@ function calculateFileName(filePath) {

return filePath;
}

function makeModuleContent(content, defaultRead, id, filePath) {
if (typeof content === 'function') {
return content(defaultRead, id, filePath);
}
if (Array.isArray(content)) {
let modules = content.map(m => `'${m}'`).join(',');
return `define([${modules}], function() { });`;
}
}

0 comments on commit fc5f197

Please sign in to comment.