Skip to content

Commit fc1ce41

Browse files
developitfilipesilva
authored andcommitted
feat(@angular-devkit/build-angular): Automatically bundle module workers.
Supports new Worker(...,{type:module}) using github.com/googlechromelabs/worker-plugin
1 parent 42ef582 commit fc1ce41

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

packages/angular/cli/lib/config/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@
836836
"ngswConfigPath": {
837837
"type": "string",
838838
"description": "Path to ngsw-config.json."
839+
},
840+
"autoBundleWorkerModules": {
841+
"type": "boolean",
842+
"description": "Automatically bundle new Worker('..', { type:'module' })",
843+
"default": true
839844
},
840845
"skipAppShell": {
841846
"type": "boolean",

packages/angular_devkit/build_angular/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"webpack-dev-server": "3.2.1",
5252
"webpack-merge": "4.2.1",
5353
"webpack-sources": "1.3.0",
54-
"webpack-subresource-integrity": "1.1.0-rc.6"
54+
"webpack-subresource-integrity": "1.1.0-rc.6",
55+
"worker-plugin": "^3.1.0"
5556
},
5657
"devDependencies": {
5758
"@angular/animations": "^8.0.0-beta.10",

packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface BuildOptions {
5454
namedChunks?: boolean;
5555
subresourceIntegrity?: boolean;
5656
serviceWorker?: boolean;
57+
autoBundleWorkerModules?: boolean;
5758
skipAppShell?: boolean;
5859
statsJson: boolean;
5960
forkTypeChecker: boolean;

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const ProgressPlugin = require('webpack/lib/ProgressPlugin');
2828
const CircularDependencyPlugin = require('circular-dependency-plugin');
2929
const TerserPlugin = require('terser-webpack-plugin');
3030
const StatsPlugin = require('stats-webpack-plugin');
31+
const WorkerPlugin = require('worker-plugin');
3132

3233

3334
// tslint:disable-next-line:no-any
@@ -133,6 +134,11 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
133134
});
134135
}
135136

137+
if (buildOptions.autoBundleWorkerModules) {
138+
const workerPluginInstance = new WorkerPlugin({ globalObject: false });
139+
extraPlugins.push(workerPluginInstance);
140+
}
141+
136142
// process asset entries
137143
if (buildOptions.assets) {
138144
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => {

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9890,6 +9890,13 @@ worker-farm@^1.5.2:
98909890
dependencies:
98919891
errno "~0.1.7"
98929892

9893+
worker-plugin@^3.1.0:
9894+
version "3.1.0"
9895+
resolved "https://registry.yarnpkg.com/worker-plugin/-/worker-plugin-3.1.0.tgz#6311778f3514a87c273510ee3f809cc3fe161e6f"
9896+
integrity sha512-iQ9KTTmmN5fhfc2KMR7CcDblvcrg1QQ4pXymqZ3cRZF8L0890YLBcEqlIsGPdxoFwghyN8RA1pCEhCKuTF4Lkw==
9897+
dependencies:
9898+
loader-utils "^1.1.0"
9899+
98939900
wrap-ansi@^2.0.0:
98949901
version "2.1.0"
98959902
resolved "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"

0 commit comments

Comments
 (0)