Skip to content

Commit b06ae55

Browse files
clydinalan-agius4
authored andcommitted
feat(@angular-devkit/build-angular): add service worker support to experimental esbuild builder
Service worker augmentation of an application is now supported when using the experimental `browser-esbuild` application builder. Both the `serviceWorker` and `ngswConfigPath` options are now available for use. The implementation leverages the `augmentAppWithServiceWorker` internal function that is used by the Webpack-based builder. This function currently reads the application files from the filesystem after all the application files are written. With the `browser-esbuild`builder, all application files are available in-memory. This can allow a future version of the service worker code to avoid additional file access and further improve build time performance when using a service worker. Future work will investigate the creation of an `augmentAppWithServiceWorker` variant that supports accessing these in-memory files.
1 parent d1e3d98 commit b06ae55

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ jobs:
221221
name: Execute CLI E2E Tests Subset with esbuild builder
222222
command: |
223223
mkdir /mnt/ramdisk/e2e-esbuild
224-
node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX} <<# parameters.snapshots >>--ng-snapshots<</ parameters.snapshots >> --esbuild --tmpdir=/mnt/ramdisk/e2e-esbuild --glob="{tests/basic/**,tests/build/prod-build.ts}" --ignore="tests/basic/{environment,rebuild,serve,scripts-array}.ts"
224+
node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX} <<# parameters.snapshots >>--ng-snapshots<</ parameters.snapshots >> --esbuild --tmpdir=/mnt/ramdisk/e2e-esbuild --glob="{tests/basic/**,tests/build/prod-build.ts,tests/commands/add/add-pwa.ts}" --ignore="tests/basic/{environment,rebuild,serve,scripts-array}.ts"
225225
- fail_fast
226226

227227
test-browsers:

packages/angular_devkit/build_angular/src/builders/browser-esbuild/experimental-warnings.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ const UNSUPPORTED_OPTIONS: Array<keyof BrowserBuilderOptions> = [
2424
// 'i18nDuplicateTranslation',
2525
// 'i18nMissingTranslation',
2626

27-
// * Serviceworker support
28-
'ngswConfigPath',
29-
'serviceWorker',
30-
3127
// * Stylesheet preprocessor support
3228
'inlineStyleLanguage',
3329
// The following option has no effect until preprocessors are supported

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { assertIsError } from '../../utils/error';
1717
import { FileInfo } from '../../utils/index-file/augment-index-html';
1818
import { IndexHtmlGenerator } from '../../utils/index-file/index-html-generator';
1919
import { generateEntryPoints } from '../../utils/package-chunk-sort';
20+
import { augmentAppWithServiceWorker } from '../../utils/service-worker';
2021
import { getIndexInputFile, getIndexOutputFile } from '../../utils/webpack-browser-config';
2122
import { resolveGlobalStyles } from '../../webpack/configs';
2223
import { Schema as BrowserBuilderOptions, SourceMapClass } from '../browser/schema';
@@ -61,6 +62,7 @@ export async function execute(
6162
}
6263

6364
const {
65+
projectRoot,
6466
workspaceRoot,
6567
mainEntryPoint,
6668
polyfillsEntryPoint,
@@ -249,6 +251,24 @@ export async function execute(
249251
outputFiles.map((file) => fs.writeFile(path.join(outputPath, file.path), file.contents)),
250252
);
251253

254+
// Augment the application with service worker support
255+
// TODO: This should eventually operate on the in-memory files prior to writing the output files
256+
if (options.serviceWorker) {
257+
try {
258+
await augmentAppWithServiceWorker(
259+
projectRoot,
260+
workspaceRoot,
261+
outputPath,
262+
options.baseHref || '/',
263+
options.ngswConfigPath,
264+
);
265+
} catch (error) {
266+
context.logger.error(error instanceof Error ? error.message : `${error}`);
267+
268+
return { success: false };
269+
}
270+
}
271+
252272
context.logger.info(`Complete. [${(Date.now() - startTime) / 1000} seconds]`);
253273

254274
return { success: true };

0 commit comments

Comments
 (0)