Skip to content

Commit 87f9943

Browse files
author
Pat Herlihy
committed
chore(webpack): Updated dist/ build files
1 parent 8970d4a commit 87f9943

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

dist/DistPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
// This plugin tries to convert a request containing `/dist/xxx/` to the configured distribution if it exists.
23
// For example new DistPlugin('native-modules') will turn
34
// ./dist/commonjs/aurelia-framework.js
@@ -9,7 +10,6 @@
910
// if the alternate distribution does not exist.
1011
// The alias configuration above will fail the build if a third party lib also uses ./dist/commonjs
1112
// but does not include a ./dist/native-modules
12-
"use strict";
1313
Object.defineProperty(exports, "__esModule", { value: true });
1414
class DistPlugin {
1515
constructor(dist) {

dist/PreserveModuleNamePlugin.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PreserveModuleNamePlugin {
2626
if (m.constructor.name === "ConcatenatedModule")
2727
modulesBeforeConcat.splice(i--, 1, ...m["modules"]);
2828
}
29-
for (let module of getPreservedModules(modules)) {
29+
for (let module of getPreservedModules(modules, alias)) {
3030
// Even though it's imported by Aurelia, it's still possible that the module
3131
// became the _root_ of a ConcatenatedModule.
3232
// We use `constructor.name` rather than `instanceof` for compat. with Webpack 2.
@@ -59,14 +59,33 @@ class PreserveModuleNamePlugin {
5959
}
6060
exports.PreserveModuleNamePlugin = PreserveModuleNamePlugin;
6161
;
62-
function getPreservedModules(modules) {
62+
function getPreservedModules(modules, aliases) {
6363
return new Set(modules.filter(m => {
6464
// Some modules might have [preserveModuleName] already set, see ConventionDependenciesPlugin.
6565
let value = m[exports.preserveModuleName];
6666
for (let r of m.reasons) {
6767
if (!r.dependency[exports.preserveModuleName])
6868
continue;
6969
value = true;
70+
// Handle aliases
71+
const raw = r.module && r.module.rawRequest;
72+
const ext = m.rawRequest && m.rawRequest.match(/^.+(\.\w+$)/);
73+
if (aliases && raw && ext) {
74+
const alias_matches = Object.keys(aliases).filter((a) => {
75+
// Absolute?
76+
if (a[a.length - 1] === '$' && a === `${raw}$`) {
77+
return true;
78+
}
79+
return !!(raw.match(new RegExp(`^${a}/`)));
80+
});
81+
// Invalid?
82+
if (alias_matches.length > 1)
83+
throw new Error(`Incorrect alias usage. "${raw}" is duplicated in ${alias_matches}`);
84+
else if (alias_matches.length === 1 && ext[1]) {
85+
m[exports.preserveModuleName] = `${raw}${ext[1]}`;
86+
return true;
87+
}
88+
}
7089
let req = removeLoaders(r.dependency.request);
7190
// We try to find an absolute string and set that as the module [preserveModuleName], as it's the best id.
7291
if (req && !req.startsWith(".")) {

0 commit comments

Comments
 (0)