Skip to content

Commit af1a745

Browse files
committed
feat(index): make naming external modules optional
adds the 'nameExternalModules' option, defaults to true
1 parent d7dec55 commit af1a745

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/index.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AureliaWebpackPlugin {
1414
constructor(options = {}) {
1515
options.root = options.root ? path.normalizeSafe(options.root) : path.dirname(module.parent.filename);
1616
options.src = options.src ? path.normalizeSafe(options.src) : path.resolve(options.root, 'src');
17+
options.nameExternalModules = options.nameExternalModules == undefined || options.nameExternalModules == true;
1718
options.resourceRegExp = options.resourceRegExp || /aurelia-loader-context/;
1819
options.customViewLoaders = Object.assign({
1920
'.css': ['css'],
@@ -214,22 +215,24 @@ class AureliaWebpackPlugin {
214215
let relativeToSrc = path.relative(options.src, module.resource);
215216
moduleId = relativeToSrc;
216217
}
217-
if (!moduleId && typeof module.userRequest == 'string') {
218-
// paths resolved as build resources
219-
let matchingModuleIds = paths
220-
.filter(originPath => contextElements[originPath].source === module.userRequest)
221-
.map(originPath => path.normalize(originPath));
222-
223-
if (matchingModuleIds.length) {
224-
matchingModuleIds.sort((a, b) => b.length - a.length);
225-
moduleId = matchingModuleIds[0];
218+
if (options.nameExternalModules) {
219+
if (!moduleId && typeof module.userRequest == 'string') {
220+
// paths resolved as build resources
221+
let matchingModuleIds = paths
222+
.filter(originPath => contextElements[originPath].source === module.userRequest)
223+
.map(originPath => path.normalize(originPath));
224+
225+
if (matchingModuleIds.length) {
226+
matchingModuleIds.sort((a, b) => b.length - a.length);
227+
moduleId = matchingModuleIds[0];
228+
}
226229
}
227-
}
228-
if (!moduleId && typeof module.rawRequest == 'string' && module.rawRequest.indexOf('.') !== 0) {
229-
// requested modules from node_modules:
230-
let index = paths.indexOf(module.rawRequest);
231-
if (index >= 0) {
232-
moduleId = module.rawRequest;
230+
if (!moduleId && typeof module.rawRequest == 'string' && module.rawRequest.indexOf('.') !== 0) {
231+
// requested modules from node_modules:
232+
let index = paths.indexOf(module.rawRequest);
233+
if (index >= 0) {
234+
moduleId = module.rawRequest;
235+
}
233236
}
234237
}
235238
if (moduleId) {

0 commit comments

Comments
 (0)