Skip to content

Commit

Permalink
fix pathing in loader
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Sep 27, 2016
1 parent b6d044a commit d6fbf39
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions packages/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ function _removeDecorators(fileName: string, source: string): string {


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

return source
.replace(/(import.*)\bplatformBrowserDynamic\b(.*\/)platform-browser-dynamic(\b.*)$/m,
'$1 platformBrowser $2platform-browser$3')
.replace(/^([\s\S]*)platformBrowserDynamic([\s\S]*).bootstrapModule([\s\S]*)Module([\s\S]*)$/m,
'$1platformBrowser$2.bootstrapModuleFactory$3ModuleNgFactory$4')
.replace(/^(import.*)\bModule\b(.*) from .*$/m,
.replace(/^(import.*\w*)Module\b(.*) from .*$/m,
`$1ModuleNgFactory$2 from '${ngFactoryPath}';`);
}

Expand All @@ -48,27 +49,29 @@ export function ngcLoader(source: string) {
if (plugin && plugin instanceof NgcWebpackPlugin) {
const cb: any = this.async();

plugin.done.then(() => {
source = _removeDecorators(this.resource, source);
source = _replaceBootstrap(this.resource, source, plugin);
plugin.done
.then(() => {
source = _removeDecorators(this.resource, source);
source = _replaceBootstrap(this.resource, source, plugin);

const result = ts.transpileModule(source, {
compilerOptions: {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.ES2015,
}
});

if (result.diagnostics && result.diagnostics.length) {
let message = '';
result.diagnostics.forEach(d => {
message += d.messageText + '\n';
const result = ts.transpileModule(source, {
compilerOptions: {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.ES2015,
}
});
cb(new Error(message));
}

cb(null, result.outputText, result.sourceMapText ? JSON.parse(result.sourceMapText) : null);
});
if (result.diagnostics && result.diagnostics.length) {
let message = '';
result.diagnostics.forEach(d => {
message += d.messageText + '\n';
});
cb(new Error(message));
}

cb(null, result.outputText, result.sourceMapText ? JSON.parse(result.sourceMapText) : null);
})
.catch(err => cb(err));
} else {
return ts.transpileModule(source, {
compilerOptions: {
Expand Down

0 comments on commit d6fbf39

Please sign in to comment.