feat(angular): add --bundler flag for applications (#17919)
This commit is contained in:
parent
55c0a168cf
commit
9eaa240b4d
@ -161,6 +161,12 @@
|
|||||||
"description": "Generate a Angular app with a minimal setup.",
|
"description": "Generate a Angular app with a minimal setup.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"bundler": {
|
||||||
|
"description": "Bundler to use to build the application.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["webpack", "esbuild"],
|
||||||
|
"default": "webpack"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|||||||
@ -53,6 +53,11 @@ describe('Angular Projects', () => {
|
|||||||
`generate @nx/angular:app ${standaloneApp} --directory=myDir --standalone=true --no-interactive`
|
`generate @nx/angular:app ${standaloneApp} --directory=myDir --standalone=true --no-interactive`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const esbuildApp = uniq('esbuild-app');
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/angular:app ${esbuildApp} --bundler=esbuild --directory=myDir --no-interactive`
|
||||||
|
);
|
||||||
|
|
||||||
updateFile(
|
updateFile(
|
||||||
`apps/${app1}/src/app/app.module.ts`,
|
`apps/${app1}/src/app/app.module.ts`,
|
||||||
`
|
`
|
||||||
@ -73,10 +78,11 @@ describe('Angular Projects', () => {
|
|||||||
|
|
||||||
// check build
|
// check build
|
||||||
runCLI(
|
runCLI(
|
||||||
`run-many --target build --projects=${app1},my-dir-${standaloneApp} --parallel --prod --output-hashing none`
|
`run-many --target build --projects=${app1},my-dir-${standaloneApp},my-dir-${esbuildApp} --parallel --prod --output-hashing none`
|
||||||
);
|
);
|
||||||
checkFilesExist(`dist/apps/${app1}/main.js`);
|
checkFilesExist(`dist/apps/${app1}/main.js`);
|
||||||
checkFilesExist(`dist/apps/my-dir/${standaloneApp}/main.js`);
|
checkFilesExist(`dist/apps/my-dir/${standaloneApp}/main.js`);
|
||||||
|
checkFilesExist(`dist/apps/my-dir/${esbuildApp}/index.html`);
|
||||||
// This is a loose requirement because there are a lot of
|
// This is a loose requirement because there are a lot of
|
||||||
// influences external from this project that affect this.
|
// influences external from this project that affect this.
|
||||||
const es2015BundleSize = getSize(tmpProjPath(`dist/apps/${app1}/main.js`));
|
const es2015BundleSize = getSize(tmpProjPath(`dist/apps/${app1}/main.js`));
|
||||||
@ -87,7 +93,7 @@ describe('Angular Projects', () => {
|
|||||||
|
|
||||||
// check unit tests
|
// check unit tests
|
||||||
runCLI(
|
runCLI(
|
||||||
`run-many --target test --projects=${app1},my-dir-${standaloneApp},${lib1} --parallel`
|
`run-many --target test --projects=${app1},my-dir-${standaloneApp},my-dir-${esbuildApp},${lib1} --parallel`
|
||||||
);
|
);
|
||||||
|
|
||||||
// check e2e tests
|
// check e2e tests
|
||||||
|
|||||||
@ -969,6 +969,27 @@ describe('app', () => {
|
|||||||
appTree.read('apps/plain/src/app/app.component.html', 'utf-8')
|
appTree.read('apps/plain/src/app/app.component.html', 'utf-8')
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should generate a correct build target for --bundler=esbuild', async () => {
|
||||||
|
await generateApp(appTree, 'ngesbuild', {
|
||||||
|
routing: true,
|
||||||
|
bundler: 'esbuild',
|
||||||
|
});
|
||||||
|
|
||||||
|
const project = readProjectConfiguration(appTree, 'ngesbuild');
|
||||||
|
expect(project.targets.build.executor).toEqual(
|
||||||
|
'@angular-devkit/build-angular:browser-esbuild'
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
project.targets.build.configurations.development.namedChunks
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
project.targets.build.configurations.development.vendorChunks
|
||||||
|
).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
project.targets.build.configurations.production.budgets
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,10 @@ import type { NormalizedSchema } from './normalized-schema';
|
|||||||
|
|
||||||
export function createProject(tree: Tree, options: NormalizedSchema) {
|
export function createProject(tree: Tree, options: NormalizedSchema) {
|
||||||
const installedAngularInfo = getInstalledAngularVersionInfo(tree);
|
const installedAngularInfo = getInstalledAngularVersionInfo(tree);
|
||||||
|
const buildExecutor =
|
||||||
|
options.bundler === 'webpack'
|
||||||
|
? '@angular-devkit/build-angular:browser'
|
||||||
|
: '@angular-devkit/build-angular:browser-esbuild';
|
||||||
const project: AngularProjectConfiguration = {
|
const project: AngularProjectConfiguration = {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
projectType: 'application',
|
projectType: 'application',
|
||||||
@ -15,7 +19,7 @@ export function createProject(tree: Tree, options: NormalizedSchema) {
|
|||||||
tags: options.parsedTags,
|
tags: options.parsedTags,
|
||||||
targets: {
|
targets: {
|
||||||
build: {
|
build: {
|
||||||
executor: '@angular-devkit/build-angular:browser',
|
executor: buildExecutor,
|
||||||
outputs: ['{options.outputPath}'],
|
outputs: ['{options.outputPath}'],
|
||||||
options: {
|
options: {
|
||||||
outputPath: `dist/${
|
outputPath: `dist/${
|
||||||
@ -37,7 +41,9 @@ export function createProject(tree: Tree, options: NormalizedSchema) {
|
|||||||
},
|
},
|
||||||
configurations: {
|
configurations: {
|
||||||
production: {
|
production: {
|
||||||
budgets: [
|
budgets:
|
||||||
|
options.bundler === 'webpack'
|
||||||
|
? [
|
||||||
{
|
{
|
||||||
type: 'initial',
|
type: 'initial',
|
||||||
maximumWarning: '500kb',
|
maximumWarning: '500kb',
|
||||||
@ -48,7 +54,8 @@ export function createProject(tree: Tree, options: NormalizedSchema) {
|
|||||||
maximumWarning: '2kb',
|
maximumWarning: '2kb',
|
||||||
maximumError: '4kb',
|
maximumError: '4kb',
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
|
: undefined,
|
||||||
fileReplacements:
|
fileReplacements:
|
||||||
installedAngularInfo.major === 14
|
installedAngularInfo.major === 14
|
||||||
? [
|
? [
|
||||||
@ -63,10 +70,10 @@ export function createProject(tree: Tree, options: NormalizedSchema) {
|
|||||||
development: {
|
development: {
|
||||||
buildOptimizer: false,
|
buildOptimizer: false,
|
||||||
optimization: false,
|
optimization: false,
|
||||||
vendorChunk: true,
|
vendorChunk: options.bundler === 'webpack' ? true : undefined,
|
||||||
extractLicenses: false,
|
extractLicenses: false,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
namedChunks: true,
|
namedChunks: options.bundler === 'webpack' ? true : undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultConfiguration: 'production',
|
defaultConfiguration: 'production',
|
||||||
|
|||||||
@ -68,6 +68,7 @@ export function normalizeOptions(
|
|||||||
e2eTestRunner: E2eTestRunner.Cypress,
|
e2eTestRunner: E2eTestRunner.Cypress,
|
||||||
linter: Linter.EsLint,
|
linter: Linter.EsLint,
|
||||||
strict: true,
|
strict: true,
|
||||||
|
bundler: options.bundler ?? 'webpack',
|
||||||
...options,
|
...options,
|
||||||
prefix,
|
prefix,
|
||||||
name: appProjectName,
|
name: appProjectName,
|
||||||
|
|||||||
@ -27,4 +27,5 @@ export interface Schema {
|
|||||||
standalone?: boolean;
|
standalone?: boolean;
|
||||||
rootProject?: boolean;
|
rootProject?: boolean;
|
||||||
minimal?: boolean;
|
minimal?: boolean;
|
||||||
|
bundler?: 'webpack' | 'esbuild';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -164,6 +164,12 @@
|
|||||||
"description": "Generate a Angular app with a minimal setup.",
|
"description": "Generate a Angular app with a minimal setup.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"bundler": {
|
||||||
|
"description": "Bundler to use to build the application.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["webpack", "esbuild"],
|
||||||
|
"default": "webpack"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user