Skip to content

Commit 72613ab

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 ef11c9f commit 72613ab

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
@@ -49,7 +49,8 @@
4949
"webpack-dev-server": "3.2.1",
5050
"webpack-merge": "4.2.1",
5151
"webpack-sources": "1.3.0",
52-
"webpack-subresource-integrity": "1.1.0-rc.6"
52+
"webpack-subresource-integrity": "1.1.0-rc.6",
53+
"worker-plugin": "^3.1.0"
5354
},
5455
"optionalDependencies": {
5556
"node-sass": "4.11.0"

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
@@ -22,6 +22,7 @@ const ProgressPlugin = require('webpack/lib/ProgressPlugin');
2222
const CircularDependencyPlugin = require('circular-dependency-plugin');
2323
const TerserPlugin = require('terser-webpack-plugin');
2424
const StatsPlugin = require('stats-webpack-plugin');
25+
const WorkerPlugin = require('worker-plugin');
2526

2627

2728
// tslint:disable-next-line:no-any
@@ -127,6 +128,11 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
127128
});
128129
}
129130

131+
if (buildOptions.autoBundleWorkerModules) {
132+
const workerPluginInstance = new WorkerPlugin({ globalObject: false });
133+
extraPlugins.push(workerPluginInstance);
134+
}
135+
130136
// process asset entries
131137
if (buildOptions.assets) {
132138
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => {

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10779,6 +10779,13 @@ worker-farm@^1.5.2:
1077910779
dependencies:
1078010780
errno "~0.1.7"
1078110781

10782+
worker-plugin@^3.1.0:
10783+
version "3.1.0"
10784+
resolved "https://registry.yarnpkg.com/worker-plugin/-/worker-plugin-3.1.0.tgz#6311778f3514a87c273510ee3f809cc3fe161e6f"
10785+
integrity sha512-iQ9KTTmmN5fhfc2KMR7CcDblvcrg1QQ4pXymqZ3cRZF8L0890YLBcEqlIsGPdxoFwghyN8RA1pCEhCKuTF4Lkw==
10786+
dependencies:
10787+
loader-utils "^1.1.0"
10788+
1078210789
wrap-ansi@^2.0.0:
1078310790
version "2.1.0"
1078410791
resolved "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"

0 commit comments

Comments
 (0)