mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 20:02:40 +08:00
refactor(@angular/cli): remove deprecated --prod
flag
BREAKING CHANGE: Deprecated option `--prod` has been removed from all builders. `--configuration production`/`-c production` should be used instead if the default configuration of the builder is not configured to `production`.
This commit is contained in:
parent
69ecddaa7d
commit
2fc7c73d7e
@ -14,14 +14,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"configuration": {
|
"configuration": {
|
||||||
"description": "One or more named builder configurations as a comma-separated list as specified in the \"configurations\" section of angular.json.\nThe builder uses the named configurations to run the given target.\nFor more information, see https://angular.io/guide/workspace-config#alternate-build-configurations.\nSetting this explicitly overrides the \"--prod\" flag.",
|
"description": "One or more named builder configurations as a comma-separated list as specified in the \"configurations\" section of angular.json.\nThe builder uses the named configurations to run the given target.\nFor more information, see https://angular.io/guide/workspace-config#alternate-build-configurations.",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"aliases": ["c"]
|
"aliases": ["c"]
|
||||||
},
|
|
||||||
"prod": {
|
|
||||||
"description": "Shorthand for \"--configuration=production\".\nSet the build configuration to the production target.\nBy default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.",
|
|
||||||
"type": "boolean",
|
|
||||||
"x-deprecated": "Use `--configuration production` instead."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -422,21 +422,6 @@ export abstract class ArchitectCommand<
|
|||||||
} else {
|
} else {
|
||||||
project = commandOptions.project;
|
project = commandOptions.project;
|
||||||
target = this.target;
|
target = this.target;
|
||||||
if (commandOptions.prod) {
|
|
||||||
const defaultConfig =
|
|
||||||
project &&
|
|
||||||
target &&
|
|
||||||
this.workspace?.projects.get(project)?.targets.get(target)?.defaultConfiguration;
|
|
||||||
|
|
||||||
this.logger.warn(
|
|
||||||
defaultConfig === 'production'
|
|
||||||
? 'Option "--prod" is deprecated: No need to use this option as this builder defaults to configuration "production".'
|
|
||||||
: 'Option "--prod" is deprecated: Use "--configuration production" instead.',
|
|
||||||
);
|
|
||||||
// The --prod flag will always be the first configuration, available to be overwritten
|
|
||||||
// by following configurations.
|
|
||||||
configuration = 'production';
|
|
||||||
}
|
|
||||||
if (commandOptions.configuration) {
|
if (commandOptions.configuration) {
|
||||||
configuration = `${configuration ? `${configuration},` : ''}${
|
configuration = `${configuration ? `${configuration},` : ''}${
|
||||||
commandOptions.configuration
|
commandOptions.configuration
|
||||||
|
@ -12,7 +12,7 @@ Run `ng generate component component-name` to generate a new component. You can
|
|||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
|
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||||
|
|
||||||
## Running unit tests
|
## Running unit tests
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@ export default async function () {
|
|||||||
|
|
||||||
// Add app routing.
|
// Add app routing.
|
||||||
// This is done automatically on a new app with --routing.
|
// This is done automatically on a new app with --routing.
|
||||||
await writeFile(appRoutingModulePath, `
|
await writeFile(
|
||||||
|
appRoutingModulePath,
|
||||||
|
`
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { Routes, RouterModule } from '@angular/router';
|
import { Routes, RouterModule } from '@angular/router';
|
||||||
|
|
||||||
@ -27,18 +29,24 @@ export default async function () {
|
|||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
export class AppRoutingModule { }
|
export class AppRoutingModule { }
|
||||||
`);
|
`,
|
||||||
await prependToFile('src/app/app.module.ts',
|
);
|
||||||
`import { AppRoutingModule } from './app-routing.module';`);
|
await prependToFile(
|
||||||
|
'src/app/app.module.ts',
|
||||||
|
`import { AppRoutingModule } from './app-routing.module';`,
|
||||||
|
);
|
||||||
await replaceInFile('src/app/app.module.ts', `imports: [`, `imports: [ AppRoutingModule,`);
|
await replaceInFile('src/app/app.module.ts', `imports: [`, `imports: [ AppRoutingModule,`);
|
||||||
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
|
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
|
||||||
|
|
||||||
const originalAppRoutingModule = await readFile(appRoutingModulePath);
|
const originalAppRoutingModule = await readFile(appRoutingModulePath);
|
||||||
// helper to replace loadChildren
|
// helper to replace loadChildren
|
||||||
const replaceLoadChildren = async (route: string) => {
|
const replaceLoadChildren = async (route: string) => {
|
||||||
const content = originalAppRoutingModule.replace('const routes: Routes = [];', `
|
const content = originalAppRoutingModule.replace(
|
||||||
|
'const routes: Routes = [];',
|
||||||
|
`
|
||||||
const routes: Routes = [{ path: 'lazy', loadChildren: ${route} }];
|
const routes: Routes = [{ path: 'lazy', loadChildren: ${route} }];
|
||||||
`);
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
return writeFile(appRoutingModulePath, content);
|
return writeFile(appRoutingModulePath, content);
|
||||||
};
|
};
|
||||||
@ -46,13 +54,19 @@ export default async function () {
|
|||||||
// Add lazy route.
|
// Add lazy route.
|
||||||
await ng('generate', 'module', 'lazy', '--routing');
|
await ng('generate', 'module', 'lazy', '--routing');
|
||||||
await ng('generate', 'component', 'lazy/lazy-comp');
|
await ng('generate', 'component', 'lazy/lazy-comp');
|
||||||
await replaceInFile('src/app/lazy/lazy-routing.module.ts', 'const routes: Routes = [];', `
|
await replaceInFile(
|
||||||
|
'src/app/lazy/lazy-routing.module.ts',
|
||||||
|
'const routes: Routes = [];',
|
||||||
|
`
|
||||||
import { LazyCompComponent } from './lazy-comp/lazy-comp.component';
|
import { LazyCompComponent } from './lazy-comp/lazy-comp.component';
|
||||||
const routes: Routes = [{ path: '', component: LazyCompComponent }];
|
const routes: Routes = [{ path: '', component: LazyCompComponent }];
|
||||||
`);
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
// Add lazy route e2e
|
// Add lazy route e2e
|
||||||
await writeFile('e2e/src/app.e2e-spec.ts', `
|
await writeFile(
|
||||||
|
'e2e/src/app.e2e-spec.ts',
|
||||||
|
`
|
||||||
import { browser, logging, element, by } from 'protractor';
|
import { browser, logging, element, by } from 'protractor';
|
||||||
|
|
||||||
describe('workspace-project App', () => {
|
describe('workspace-project App', () => {
|
||||||
@ -69,11 +83,12 @@ export default async function () {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
`);
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
// Convert the default config to use JIT and prod to just do AOT.
|
// Convert the default config to use JIT and prod to just do AOT.
|
||||||
// This way we can use `ng e2e` to test JIT and `ng e2e --prod` to test AOT.
|
// This way we can use `ng e2e` to test JIT and `ng e2e --configuration=production` to test AOT.
|
||||||
await updateJsonFile('angular.json', json => {
|
await updateJsonFile('angular.json', (json) => {
|
||||||
const buildTarget = json['projects'][projectName]['architect']['build'];
|
const buildTarget = json['projects'][projectName]['architect']['build'];
|
||||||
buildTarget['options']['aot'] = true;
|
buildTarget['options']['aot'] = true;
|
||||||
buildTarget['configurations']['development']['aot'] = false;
|
buildTarget['configurations']['development']['aot'] = false;
|
||||||
|
@ -7,7 +7,7 @@ import { isPrereleaseCli, updateJsonFile } from '../../utils/project';
|
|||||||
const snapshots = require('../../ng-snapshot/package.json');
|
const snapshots = require('../../ng-snapshot/package.json');
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
const tag = await isPrereleaseCli() ? '@next' : '';
|
const tag = (await isPrereleaseCli()) ? '@next' : '';
|
||||||
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
|
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
|
||||||
|
|
||||||
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
|
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
|
||||||
@ -72,5 +72,5 @@ export default async function () {
|
|||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await ng('e2e', '--prod');
|
await ng('e2e', '--configuration=production');
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,11 @@ export default async function() {
|
|||||||
|
|
||||||
let error;
|
let error;
|
||||||
try {
|
try {
|
||||||
await execAndWaitForOutputToMatch('ng', ['serve', '--prod'], webpackGoodRegEx);
|
await execAndWaitForOutputToMatch(
|
||||||
|
'ng',
|
||||||
|
['serve', '--configuration=production'],
|
||||||
|
webpackGoodRegEx,
|
||||||
|
);
|
||||||
|
|
||||||
await wait(4000);
|
await wait(4000);
|
||||||
|
|
||||||
|
@ -3,17 +3,19 @@ import { installWorkspacePackages } from '../../utils/packages';
|
|||||||
import { ng } from '../../utils/process';
|
import { ng } from '../../utils/process';
|
||||||
import { updateJsonFile } from '../../utils/project';
|
import { updateJsonFile } from '../../utils/project';
|
||||||
|
|
||||||
export default function () {
|
export default async function () {
|
||||||
return updateJsonFile('package.json', packageJson => {
|
await updateJsonFile('package.json', (packageJson) => {
|
||||||
// Install ngrx
|
// Install ngrx
|
||||||
packageJson['dependencies']['@ngrx/effects'] = '^9.1.0';
|
packageJson['dependencies']['@ngrx/effects'] = '^9.1.0';
|
||||||
packageJson['dependencies']['@ngrx/schematics'] = '^9.1.0';
|
packageJson['dependencies']['@ngrx/schematics'] = '^9.1.0';
|
||||||
packageJson['dependencies']['@ngrx/store'] = '^9.1.0';
|
packageJson['dependencies']['@ngrx/store'] = '^9.1.0';
|
||||||
packageJson['dependencies']['@ngrx/store-devtools'] = '^9.1.0';
|
packageJson['dependencies']['@ngrx/store-devtools'] = '^9.1.0';
|
||||||
})
|
});
|
||||||
.then(() => installWorkspacePackages())
|
|
||||||
|
await installWorkspacePackages();
|
||||||
|
|
||||||
// Create an app that uses ngrx decorators and has e2e tests.
|
// Create an app that uses ngrx decorators and has e2e tests.
|
||||||
.then(_ => writeMultipleFiles({
|
await writeMultipleFiles({
|
||||||
'./e2e/src/app.po.ts': `
|
'./e2e/src/app.po.ts': `
|
||||||
import { browser, by, element } from 'protractor';
|
import { browser, by, element } from 'protractor';
|
||||||
export class AppPage {
|
export class AppPage {
|
||||||
@ -155,7 +157,8 @@ export default function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
}))
|
});
|
||||||
// Run the e2e tests against a prod build.
|
|
||||||
.then(() => ng('e2e', '--prod'));
|
// Run the e2e tests against a production build.
|
||||||
|
await ng('e2e', '--configuration=production');
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ import { updateJsonFile } from '../../utils/project';
|
|||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
// Tests run in 'dev' environment by default.
|
// Tests run in 'dev' environment by default.
|
||||||
return writeFile('src/app/environment.spec.ts', `
|
return (
|
||||||
|
writeFile(
|
||||||
|
'src/app/environment.spec.ts',
|
||||||
|
`
|
||||||
import { environment } from '../environments/environment';
|
import { environment } from '../environments/environment';
|
||||||
|
|
||||||
describe('Test environment', () => {
|
describe('Test environment', () => {
|
||||||
@ -12,9 +15,11 @@ export default function () {
|
|||||||
expect(environment.production).toBe(false);
|
expect(environment.production).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
`)
|
`,
|
||||||
|
)
|
||||||
.then(() => ng('test', '--watch=false'))
|
.then(() => ng('test', '--watch=false'))
|
||||||
.then(() => updateJsonFile('angular.json', configJson => {
|
.then(() =>
|
||||||
|
updateJsonFile('angular.json', (configJson) => {
|
||||||
const appArchitect = configJson.projects['test-project'].architect;
|
const appArchitect = configJson.projects['test-project'].architect;
|
||||||
appArchitect.test.configurations = {
|
appArchitect.test.configurations = {
|
||||||
production: {
|
production: {
|
||||||
@ -22,14 +27,18 @@ export default function () {
|
|||||||
{
|
{
|
||||||
src: 'src/environments/environment.ts',
|
src: 'src/environments/environment.ts',
|
||||||
replaceWith: 'src/environments/environment.prod.ts',
|
replaceWith: 'src/environments/environment.prod.ts',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
// Tests can run in different environment.
|
// Tests can run in different environment.
|
||||||
.then(() => writeFile('src/app/environment.spec.ts', `
|
.then(() =>
|
||||||
|
writeFile(
|
||||||
|
'src/app/environment.spec.ts',
|
||||||
|
`
|
||||||
import { environment } from '../environments/environment';
|
import { environment } from '../environments/environment';
|
||||||
|
|
||||||
describe('Test environment', () => {
|
describe('Test environment', () => {
|
||||||
@ -37,6 +46,9 @@ export default function () {
|
|||||||
expect(environment.production).toBe(true);
|
expect(environment.production).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
`))
|
`,
|
||||||
.then(() => ng('test', '--prod', '--watch=false'));
|
),
|
||||||
|
)
|
||||||
|
.then(() => ng('test', '--configuration=production', '--watch=false'))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ export default async function () {
|
|||||||
await ng('generate', 'component', 'my-comp');
|
await ng('generate', 'component', 'my-comp');
|
||||||
await ng('test', '--watch=false');
|
await ng('test', '--watch=false');
|
||||||
await ng('e2e');
|
await ng('e2e');
|
||||||
await ng('e2e', '--prod');
|
await ng('e2e', '--configuration=production');
|
||||||
|
|
||||||
// Verify project now creates bundles
|
// Verify project now creates bundles
|
||||||
await noSilentNg('build', '--prod');
|
await noSilentNg('build', '--configuration=production');
|
||||||
await expectFileMatchToExist('dist/nine-project/', /main\.[0-9a-f]{16}\.js/);
|
await expectFileMatchToExist('dist/nine-project/', /main\.[0-9a-f]{16}\.js/);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user