Skip to content

Web Worker support #13700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(@ngtools/webpack): reuse compiler host in webpack child compilat…
…ions
  • Loading branch information
filipesilva committed Apr 1, 2019
commit 224cbe1b4e970af003efa34017d2f20c2ff79ac9
26 changes: 24 additions & 2 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ export class AngularCompilerPlugin {

// Registration hook for webpack plugin.
// tslint:disable-next-line:no-big-function
apply(compiler: Compiler & { watchMode?: boolean }) {
apply(compiler: Compiler & { watchMode?: boolean, parentCompilation?: compilation.Compilation }) {
// The below is require by NGCC processor
// since we need to know which fields we need to process
compiler.hooks.environment.tap('angular-compiler', () => {
Expand All @@ -610,8 +610,14 @@ export class AngularCompilerPlugin {
// cleanup if not watching
compiler.hooks.thisCompilation.tap('angular-compiler', compilation => {
compilation.hooks.finishModules.tap('angular-compiler', () => {
let rootCompiler = compiler;
while (rootCompiler.parentCompilation) {
// tslint:disable-next-line:no-any
rootCompiler = compiler.parentCompilation as any;
}

// only present for webpack 4.23.0+, assume true otherwise
const watchMode = compiler.watchMode === undefined ? true : compiler.watchMode;
const watchMode = rootCompiler.watchMode === undefined ? true : rootCompiler.watchMode;
if (!watchMode) {
this._program = null;
this._transformers = [];
Expand Down Expand Up @@ -859,6 +865,22 @@ export class AngularCompilerPlugin {
throw new Error('An @ngtools/webpack plugin already exist for this compilation.');
}

// If there is no compiler host at this point, it means that the environment hook did not run.
// This happens in child compilations that inherit the parent compilation file system.
if (this._compilerHost === undefined) {
const inputFs = compilation.compiler.inputFileSystem as VirtualFileSystemDecorator;
if (!inputFs.getWebpackCompilerHost) {
throw new Error('AngularCompilerPlugin is running in a child compilation, but could' +
'not find a WebpackCompilerHost in the parent compilation.');
}

// Use the existing WebpackCompilerHost to ensure builds and rebuilds work.
this._compilerHost = createCompilerHost({
options: this._compilerOptions,
tsHost: inputFs.getWebpackCompilerHost(),
}) as CompilerHost & WebpackCompilerHost;
}

// Set a private variable for this plugin instance.
// tslint:disable-next-line:no-any
(compilation as any)._ngToolsWebpackPluginInstance = this;
Expand Down
4 changes: 4 additions & 0 deletions packages/ngtools/webpack/src/virtual_file_system_decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
private _webpackCompilerHost: WebpackCompilerHost,
) { }

getWebpackCompilerHost() {
return this._webpackCompilerHost;
}

getVirtualFilesPaths() {
return this._webpackCompilerHost.getNgFactoryPaths();
}
Expand Down