Skip to content

Commit 2be135e

Browse files
committed
fix pathing in loader
1 parent b6d044a commit 2be135e

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

packages/webpack/src/loader.ts

+25-22
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ function _removeDecorators(fileName: string, source: string): string {
2727

2828

2929
function _replaceBootstrap(fileName: string, source: string, plugin: NgcWebpackPlugin) {
30-
const dirName = path.dirname(fileName);
31-
const entryModuleName = plugin.entryModule.split('#')[0] + '.ngfactory';
32-
const entryModule = path.join(plugin.genDir, path.relative(dirName, entryModuleName));
33-
const ngFactoryPath = './' + path.relative(dirName, entryModule);
30+
const basePath = plugin.angularCompilerOptions.basePath;
31+
const entryModuleFileName = plugin.entryModule.split('#')[0] + '.ngfactory';
32+
const relativeEntryModulePath = path.relative(basePath, entryModuleFileName);
33+
const fullEntryModulePath = path.resolve(plugin.genDir, relativeEntryModulePath);
34+
const ngFactoryPath = './' + path.relative(path.dirname(fileName), fullEntryModulePath);
3435

3536
return source
3637
.replace(/(import.*)\bplatformBrowserDynamic\b(.*\/)platform-browser-dynamic(\b.*)$/m,
@@ -48,27 +49,29 @@ export function ngcLoader(source: string) {
4849
if (plugin && plugin instanceof NgcWebpackPlugin) {
4950
const cb: any = this.async();
5051

51-
plugin.done.then(() => {
52-
source = _removeDecorators(this.resource, source);
53-
source = _replaceBootstrap(this.resource, source, plugin);
52+
plugin.done
53+
.then(() => {
54+
source = _removeDecorators(this.resource, source);
55+
source = _replaceBootstrap(this.resource, source, plugin);
5456

55-
const result = ts.transpileModule(source, {
56-
compilerOptions: {
57-
target: ts.ScriptTarget.ES5,
58-
module: ts.ModuleKind.ES2015,
59-
}
60-
});
61-
62-
if (result.diagnostics && result.diagnostics.length) {
63-
let message = '';
64-
result.diagnostics.forEach(d => {
65-
message += d.messageText + '\n';
57+
const result = ts.transpileModule(source, {
58+
compilerOptions: {
59+
target: ts.ScriptTarget.ES5,
60+
module: ts.ModuleKind.ES2015,
61+
}
6662
});
67-
cb(new Error(message));
68-
}
6963

70-
cb(null, result.outputText, result.sourceMapText ? JSON.parse(result.sourceMapText) : null);
71-
});
64+
if (result.diagnostics && result.diagnostics.length) {
65+
let message = '';
66+
result.diagnostics.forEach(d => {
67+
message += d.messageText + '\n';
68+
});
69+
cb(new Error(message));
70+
}
71+
72+
cb(null, result.outputText, result.sourceMapText ? JSON.parse(result.sourceMapText) : null);
73+
})
74+
.catch(err => cb(err));
7275
} else {
7376
return ts.transpileModule(source, {
7477
compilerOptions: {

0 commit comments

Comments
 (0)