diff --git a/packages/angular-cli/models/webpack-build-typescript.ts b/packages/angular-cli/models/webpack-build-typescript.ts index d23ad7ab074c..b574f56bc9bc 100644 --- a/packages/angular-cli/models/webpack-build-typescript.ts +++ b/packages/angular-cli/models/webpack-build-typescript.ts @@ -61,9 +61,9 @@ export const getWebpackAotConfigPartial = function(projectRoot: string, appConfi plugins: [ new NgcWebpackPlugin({ project: path.resolve(projectRoot, appConfig.root, appConfig.tsconfig), - baseDir: path.resolve(projectRoot, ''), + baseDir: path.resolve(projectRoot, appConfig.root), main: path.join(projectRoot, appConfig.root, appConfig.main), - genDir: path.resolve(projectRoot, '') + genDir: path.resolve(projectRoot, appConfig.root) }), ] }; diff --git a/packages/webpack/src/compiler_host.ts b/packages/webpack/src/compiler_host.ts index a65c46053896..a97e0c57d265 100644 --- a/packages/webpack/src/compiler_host.ts +++ b/packages/webpack/src/compiler_host.ts @@ -91,6 +91,7 @@ export class WebpackCompilerHost implements ts.CompilerHost { private _delegate: ts.CompilerHost; private _files: {[path: string]: VirtualFileStats} = Object.create(null); private _directories: {[path: string]: VirtualDirStats} = Object.create(null); + private _changed = false; constructor(private _options: ts.CompilerOptions, private _setParentNodes = true) { this._delegate = ts.createCompilerHost(this._options, this._setParentNodes); @@ -104,10 +105,15 @@ export class WebpackCompilerHost implements ts.CompilerHost { this._directories[p] = new VirtualDirStats(p); p = dirname(p); } + + this._changed = true; } populateWebpackResolver(resolver: any) { const fs = resolver.fileSystem; + if (!this._changed) { + return; + } for (const fileName of Object.keys(this._files)) { const stats = this._files[fileName]; @@ -121,6 +127,8 @@ export class WebpackCompilerHost implements ts.CompilerHost { fs._statStorage.data[path] = [null, stats]; fs._readdirStorage.data[path] = [null, files.concat(dirs)]; } + + this._changed = false; } fileExists(fileName: string): boolean { diff --git a/packages/webpack/src/plugin.ts b/packages/webpack/src/plugin.ts index 92201ad1c9d8..1877d11b06d4 100644 --- a/packages/webpack/src/plugin.ts +++ b/packages/webpack/src/plugin.ts @@ -98,14 +98,15 @@ export class NgcWebpackPlugin { return callback(); } - result.resource = this.genDir; - result.recursive = true; - result.dependencies.forEach((d: any) => d.critical = false); - result.resolveDependencies = createResolveDependenciesFromContextMap((_: any, cb: any) => { - return cb(null, this.lazyRoutes); + this.done.then(() => { + result.resource = this.genDir; + result.recursive = true; + result.dependencies.forEach((d: any) => d.critical = false); + result.resolveDependencies = createResolveDependenciesFromContextMap( + (_: any, cb: any) => cb(null, this.lazyRoutes)); + + return callback(null, result); }); - - return callback(null, result); }); }); @@ -119,7 +120,7 @@ export class NgcWebpackPlugin { // Virtual file system. compiler.resolvers.normal.plugin('resolve', (request: any, cb?: () => void) => { - // populate the file system cache with the virtual module + // Populate the file system cache with the virtual module. this.compilerHost.populateWebpackResolver(compiler.resolvers.normal); if (cb) { cb(); diff --git a/tests/e2e/tests/test/e2e.ts b/tests/e2e/tests/test/e2e.ts index b0e49f05286d..ca66091906c7 100644 --- a/tests/e2e/tests/test/e2e.ts +++ b/tests/e2e/tests/test/e2e.ts @@ -17,5 +17,7 @@ export default function() { return expectToFail(() => ng('e2e')) // These should work. .then(() => _runServeAndE2e()) - .then(() => _runServeAndE2e('--prod')); + .then(() => _runServeAndE2e('--prod')) + .then(() => _runServeAndE2e('--aot')) + .then(() => _runServeAndE2e('--aot', '--prod')); }