diff --git a/packages/angular/cli/lib/config/schema.json b/packages/angular/cli/lib/config/schema.json index 0e0383fbe6d6..44748d4e9e0f 100644 --- a/packages/angular/cli/lib/config/schema.json +++ b/packages/angular/cli/lib/config/schema.json @@ -836,6 +836,11 @@ "ngswConfigPath": { "type": "string", "description": "Path to ngsw-config.json." + }, + "autoBundleWorkerModules": { + "type": "boolean", + "description": "Automatically bundle new Worker('..', { type:'module' })", + "default": true }, "skipAppShell": { "type": "boolean", diff --git a/packages/angular_devkit/build_angular/package.json b/packages/angular_devkit/build_angular/package.json index d7e47486d2d0..7195f774e6df 100644 --- a/packages/angular_devkit/build_angular/package.json +++ b/packages/angular_devkit/build_angular/package.json @@ -51,7 +51,8 @@ "webpack-dev-server": "3.2.1", "webpack-merge": "4.2.1", "webpack-sources": "1.3.0", - "webpack-subresource-integrity": "1.1.0-rc.6" + "webpack-subresource-integrity": "1.1.0-rc.6", + "worker-plugin": "3.1.0" }, "devDependencies": { "@angular/animations": "^8.0.0-beta.10", diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts index 993ae9593239..8cc3c4e6635d 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts @@ -54,6 +54,7 @@ export interface BuildOptions { namedChunks?: boolean; subresourceIntegrity?: boolean; serviceWorker?: boolean; + autoBundleWorkerModules?: boolean; skipAppShell?: boolean; statsJson: boolean; forkTypeChecker: boolean; diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts index a9c03738a641..fc8f334ba67d 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts @@ -28,6 +28,7 @@ const ProgressPlugin = require('webpack/lib/ProgressPlugin'); const CircularDependencyPlugin = require('circular-dependency-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const StatsPlugin = require('stats-webpack-plugin'); +const WorkerPlugin = require('worker-plugin'); // tslint:disable-next-line:no-any @@ -133,6 +134,11 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { }); } + if (buildOptions.autoBundleWorkerModules) { + const workerPluginInstance = new WorkerPlugin({ globalObject: false }); + extraPlugins.push(workerPluginInstance); + } + // process asset entries if (buildOptions.assets) { const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => { diff --git a/yarn.lock b/yarn.lock index d144f82dbb4c..aa3afddc7554 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9897,6 +9897,13 @@ worker-farm@^1.5.2: dependencies: errno "~0.1.7" +worker-plugin@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/worker-plugin/-/worker-plugin-3.1.0.tgz#6311778f3514a87c273510ee3f809cc3fe161e6f" + integrity sha512-iQ9KTTmmN5fhfc2KMR7CcDblvcrg1QQ4pXymqZ3cRZF8L0890YLBcEqlIsGPdxoFwghyN8RA1pCEhCKuTF4Lkw== + dependencies: + loader-utils "^1.1.0" + wrap-ansi@^2.0.0: version "2.1.0" resolved "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"