Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): add externalDependencies to th…
Browse files Browse the repository at this point in the history
…e esbuild browser builder

This commit add a new `externalDependencies` option to the experimental browser builder.

Dependencies listed in this option will not be included in the final bundle, instead the user would need to provide them at runtime using import maps or another method.

Closes #23322
  • Loading branch information
alan-agius4 authored and dgp1130 committed Jun 21, 2022
1 parent 0d50661 commit a7709b7
Show file tree
Hide file tree
Showing 5 changed files with 591 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/angular_devkit/build_angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ ts_json_schema(
src = "src/builders/browser/schema.json",
)

ts_json_schema(
name = "browser_esbuild_schema",
src = "src/builders/browser-esbuild/schema.json",
)

ts_json_schema(
name = "dev_server_schema",
src = "src/builders/dev-server/schema.json",
Expand Down Expand Up @@ -70,6 +75,7 @@ ts_library(
) + [
"//packages/angular_devkit/build_angular:src/builders/app-shell/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/browser/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/browser-esbuild/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/dev-server/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/extract-i18n/schema.ts",
"//packages/angular_devkit/build_angular:src/builders/karma/schema.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/builders.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"browser-esbuild": {
"implementation": "./src/builders/browser-esbuild",
"schema": "./src/builders/browser/schema.json",
"schema": "./src/builders/browser-esbuild/schema.json",
"description": "Build a browser application."
},
"dev-server": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import { generateEntryPoints } from '../../utils/package-chunk-sort';
import { augmentAppWithServiceWorker } from '../../utils/service-worker';
import { getIndexInputFile, getIndexOutputFile } from '../../utils/webpack-browser-config';
import { resolveGlobalStyles } from '../../webpack/configs';
import { Schema as BrowserBuilderOptions, SourceMapClass } from '../browser/schema';
import { createCompilerPlugin } from './compiler-plugin';
import { DEFAULT_OUTDIR, bundle, logMessages } from './esbuild';
import { logExperimentalWarnings } from './experimental-warnings';
import { normalizeOptions } from './options';
import { Schema as BrowserBuilderOptions, SourceMapClass } from './schema';
import { bundleStylesheetText } from './stylesheets';

/**
Expand All @@ -35,7 +35,7 @@ import { bundleStylesheetText } from './stylesheets';
* @returns A promise with the builder result output
*/
// eslint-disable-next-line max-lines-per-function
export async function execute(
export async function buildEsbuildBrowser(
options: BrowserBuilderOptions,
context: BuilderContext,
): Promise<BuilderOutput> {
Expand Down Expand Up @@ -312,6 +312,7 @@ async function bundleCode(
sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
splitting: true,
tsconfig,
external: options.externalDependencies,
write: false,
platform: 'browser',
preserveSymlinks: options.preserveSymlinks,
Expand Down Expand Up @@ -339,4 +340,4 @@ async function bundleCode(
});
}

export default createBuilder(execute);
export default createBuilder(buildEsbuildBrowser);
Loading

0 comments on commit a7709b7

Please sign in to comment.