Skip to content

Commit

Permalink
chore(webpack): Updated dist/ build files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Herlihy committed Sep 5, 2017
1 parent 8970d4a commit 87f9943
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/DistPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
// This plugin tries to convert a request containing `/dist/xxx/` to the configured distribution if it exists.
// For example new DistPlugin('native-modules') will turn
// ./dist/commonjs/aurelia-framework.js
Expand All @@ -9,7 +10,6 @@
// if the alternate distribution does not exist.
// The alias configuration above will fail the build if a third party lib also uses ./dist/commonjs
// but does not include a ./dist/native-modules
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DistPlugin {
constructor(dist) {
Expand Down
23 changes: 21 additions & 2 deletions dist/PreserveModuleNamePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PreserveModuleNamePlugin {
if (m.constructor.name === "ConcatenatedModule")
modulesBeforeConcat.splice(i--, 1, ...m["modules"]);
}
for (let module of getPreservedModules(modules)) {
for (let module of getPreservedModules(modules, alias)) {
// Even though it's imported by Aurelia, it's still possible that the module
// became the _root_ of a ConcatenatedModule.
// We use `constructor.name` rather than `instanceof` for compat. with Webpack 2.
Expand Down Expand Up @@ -59,14 +59,33 @@ class PreserveModuleNamePlugin {
}
exports.PreserveModuleNamePlugin = PreserveModuleNamePlugin;
;
function getPreservedModules(modules) {
function getPreservedModules(modules, aliases) {
return new Set(modules.filter(m => {
// Some modules might have [preserveModuleName] already set, see ConventionDependenciesPlugin.
let value = m[exports.preserveModuleName];
for (let r of m.reasons) {
if (!r.dependency[exports.preserveModuleName])
continue;
value = true;
// Handle aliases
const raw = r.module && r.module.rawRequest;
const ext = m.rawRequest && m.rawRequest.match(/^.+(\.\w+$)/);
if (aliases && raw && ext) {
const alias_matches = Object.keys(aliases).filter((a) => {
// Absolute?
if (a[a.length - 1] === '$' && a === `${raw}$`) {
return true;
}
return !!(raw.match(new RegExp(`^${a}/`)));
});
// Invalid?
if (alias_matches.length > 1)
throw new Error(`Incorrect alias usage. "${raw}" is duplicated in ${alias_matches}`);
else if (alias_matches.length === 1 && ext[1]) {
m[exports.preserveModuleName] = `${raw}${ext[1]}`;
return true;
}
}
let req = removeLoaders(r.dependency.request);
// We try to find an absolute string and set that as the module [preserveModuleName], as it's the best id.
if (req && !req.startsWith(".")) {
Expand Down

0 comments on commit 87f9943

Please sign in to comment.