Skip to content

Commit 50380f8

Browse files
MartoYankovSvetoslavTsenov
authored andcommitted
refactor(core webpack): enable more module aliases to work with webpack (NativeScript#5177)
Currently only "main/main-page" and "./main/main-page.js" work. Enable "./main/main-page" and "main/main-page.js". Note that "main/main-page.ts" for TS will not work. It doesn't work without webpack too.
1 parent f6907be commit 50380f8

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tns-core-modules/globals/globals.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,20 @@ global.registerWebpackModules = function registerWebpackModules(context: Context
5757

5858
const registerName = base + registerExt;
5959
if (registerName.startsWith("./") && registerName.endsWith(".js")) {
60-
const jsNickName = registerName.substr(2, registerName.length - 5);
61-
// This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc);
62-
if (isSourceFile || !global.moduleExists(jsNickName)) {
63-
global.registerModule(jsNickName, () => context(key));
64-
}
60+
const jsNickNames = [
61+
// This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc);
62+
registerName.substr(2, registerName.length - 5),
63+
// This is for supporting module names like "./main/main-page"
64+
registerName.substr(0, registerName.length - 3),
65+
// This is for supporting module names like "main/main-page.js"
66+
registerName.substr(2),
67+
];
68+
69+
jsNickNames.forEach(jsNickName => {
70+
if (isSourceFile || !global.moduleExists(jsNickName)) {
71+
global.registerModule(jsNickName, () => context(key));
72+
}
73+
});
6574
}
6675
if (isSourceFile || !global.moduleExists(registerName)) {
6776
global.registerModule(registerName, () => context(key));

0 commit comments

Comments
 (0)