Skip to content

Commit 1960433

Browse files
committed
feat(@ngtools/webpack): Automatically bundle module workers.
Supports new Worker(...,{type:module}) using github.com/googlechromelabs/worker-plugin
1 parent 237c893 commit 1960433

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

Diff for: packages/angular/cli/lib/config/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@
752752
"description": "Generates a service worker config for production builds.",
753753
"default": false
754754
},
755+
"autoBundleWorkerModules": {
756+
"type": "boolean",
757+
"description": "Automatically bundle new Worker('..', { type:'module' })",
758+
"default": true
759+
},
755760
"skipAppShell": {
756761
"type": "boolean",
757762
"description": "Flag to prevent building an app shell.",

Diff for: packages/angular_devkit/build_angular/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"loader-utils": "1.1.0",
2828
"mini-css-extract-plugin": "0.4.3",
2929
"minimatch": "3.0.4",
30-
"parse5": "4.0.0",
3130
"opn": "5.3.0",
31+
"parse5": "4.0.0",
3232
"portfinder": "1.0.17",
3333
"postcss": "6.0.23",
3434
"postcss-import": "11.1.0",
@@ -37,21 +37,22 @@
3737
"rxjs": "6.3.3",
3838
"sass-loader": "7.1.0",
3939
"semver": "5.5.1",
40-
"source-map-support": "0.5.9",
4140
"source-map-loader": "0.2.4",
41+
"source-map-support": "0.5.9",
4242
"speed-measure-webpack-plugin": "^1.2.3",
4343
"stats-webpack-plugin": "0.7.0",
4444
"style-loader": "0.23.0",
4545
"stylus": "0.54.5",
4646
"stylus-loader": "3.0.2",
47-
"tree-kill": "1.2.0",
4847
"terser-webpack-plugin": "1.1.0",
48+
"tree-kill": "1.2.0",
4949
"webpack": "4.19.1",
5050
"webpack-dev-middleware": "3.3.0",
5151
"webpack-dev-server": "3.1.8",
5252
"webpack-merge": "4.1.4",
5353
"webpack-sources": "1.2.0",
54-
"webpack-subresource-integrity": "1.1.0-rc.6"
54+
"webpack-subresource-integrity": "1.1.0-rc.6",
55+
"worker-plugin": "^1.1.1"
5556
},
5657
"optionalDependencies": {
5758
"node-sass": "4.9.3"
@@ -87,4 +88,4 @@
8788
"protractor": "~5.4.0",
8889
"zone.js": "^0.8.19"
8990
}
90-
}
91+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface BuildOptions {
4949
namedChunks?: boolean;
5050
subresourceIntegrity?: boolean;
5151
serviceWorker?: boolean;
52+
autoBundleWorkerModules?: boolean;
5253
skipAppShell?: boolean;
5354
statsJson: boolean;
5455
forkTypeChecker: boolean;

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

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import * as path from 'path';
1212
import { HashedModuleIdsPlugin, debug } from 'webpack';
1313
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
14+
import * as WorkerPlugin from 'worker-plugin';
1415
import { getOutputHashFormat } from './utils';
1516
import { isDirectory } from '../../utilities/is-directory';
1617
import { requireProjectModule } from '../../utilities/require-project-module';
@@ -120,6 +121,11 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
120121
});
121122
}
122123

124+
if (buildOptions.autoBundleWorkerModules) {
125+
const workerPluginInstance = new WorkerPlugin();
126+
extraPlugins.push(workerPluginInstance);
127+
}
128+
123129
// process asset entries
124130
if (buildOptions.assets) {
125131
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternObject) => {

0 commit comments

Comments
 (0)