Skip to content

Commit

Permalink
feat(angular): add "prebundle" option to dev-server executor (#21752)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Feb 10, 2024
1 parent 1ba7662 commit 6a911c3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
18 changes: 18 additions & 0 deletions docs/generated/packages/angular/executors/dev-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@
"type": "number",
"description": "Enable and define the file watching poll time period in milliseconds."
},
"prebundle": {
"description": "Enable and control the Vite-based development server's prebundling capabilities. To enable prebundling, the Angular CLI cache must also be enabled. This option has no effect when using the 'browser' or other Webpack-based builders. _Note: this is only supported in Angular versions >= 17.2.0_.",
"oneOf": [
{ "type": "boolean" },
{
"type": "object",
"properties": {
"exclude": {
"description": "List of package imports that should not be prebundled by the development server. The packages will be bundled into the application code itself.",
"type": "array",
"items": { "type": "string" }
}
},
"additionalProperties": false,
"required": ["exclude"]
}
]
},
"buildLibsFromSource": {
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.",
Expand Down
11 changes: 2 additions & 9 deletions packages/angular/src/builders/dev-server/dev-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
mergeCustomWebpackConfig,
resolveIndexHtmlTransformer,
} from '../utilities/webpack';
import { normalizeOptions } from './lib';
import { normalizeOptions, validateOptions } from './lib';
import type {
NormalizedSchema,
Schema,
Expand All @@ -55,14 +55,7 @@ export function executeDevServerBuilder(
rawOptions: Schema,
context: import('@angular-devkit/architect').BuilderContext
) {
if (rawOptions.esbuildMiddleware?.length > 0) {
const { major: angularMajorVersion, version: angularVersion } =
getInstalledAngularVersionInfo();
if (angularMajorVersion < 17) {
throw new Error(stripIndents`The "esbuildMiddleware" option is only supported in Angular >= 17.0.0. You are currently using "${angularVersion}".
You can resolve this error by removing the "esbuildMiddleware" option or by migrating to Angular 17.0.0.`);
}
}
validateOptions(rawOptions);

process.env.NX_TSCONFIG_PATH = getRootTsConfigPath();

Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/builders/dev-server/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './normalize-options';
export * from './validate-options';
19 changes: 19 additions & 0 deletions packages/angular/src/builders/dev-server/lib/validate-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { stripIndents } from '@nx/devkit';
import { lt } from 'semver';
import { getInstalledAngularVersionInfo } from '../../../executors/utilities/angular-version-utils';
import type { Schema } from '../schema';

export function validateOptions(options: Schema): void {
const { major: angularMajorVersion, version: angularVersion } =
getInstalledAngularVersionInfo();

if (angularMajorVersion < 17 && options.esbuildMiddleware?.length > 0) {
throw new Error(stripIndents`The "esbuildMiddleware" option is only supported in Angular >= 17.0.0. You are currently using "${angularVersion}".
You can resolve this error by removing the "esbuildMiddleware" option or by migrating to Angular 17.0.0.`);
}

if (lt(angularVersion, '17.2.0') && options.prebundle) {
throw new Error(stripIndents`The "prebundle" option is only supported in Angular >= 17.2.0. You are currently using "${angularVersion}".
You can resolve this error by removing the "prebundle" option or by migrating to Angular 17.2.0.`);
}
}
1 change: 1 addition & 0 deletions packages/angular/src/builders/dev-server/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface BaseSchema {
hmr?: boolean;
watch?: boolean;
poll?: number;
prebundle?: boolean | { exclude: string[] };
buildLibsFromSource?: boolean;
esbuildMiddleware?: string[];
}
Expand Down
18 changes: 18 additions & 0 deletions packages/angular/src/builders/dev-server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@
"type": "number",
"description": "Enable and define the file watching poll time period in milliseconds."
},
"prebundle": {
"description": "Enable and control the Vite-based development server's prebundling capabilities. To enable prebundling, the Angular CLI cache must also be enabled. This option has no effect when using the 'browser' or other Webpack-based builders. _Note: this is only supported in Angular versions >= 17.2.0_.",
"oneOf": [
{ "type": "boolean" },
{
"type": "object",
"properties": {
"exclude": {
"description": "List of package imports that should not be prebundled by the development server. The packages will be bundled into the application code itself.",
"type": "array",
"items": { "type": "string" }
}
},
"additionalProperties": false,
"required": ["exclude"]
}
]
},
"buildLibsFromSource": {
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.",
Expand Down

0 comments on commit 6a911c3

Please sign in to comment.