in packages/schematics/angular/application/index.ts [62:243]
function addAppToWorkspaceFile(
options: ApplicationOptions,
appDir: string,
folderName: string,
): Rule {
let projectRoot = appDir;
if (projectRoot) {
projectRoot += '/';
}
const schematics: JsonObject = {};
if (
options.inlineTemplate ||
options.inlineStyle ||
options.minimal ||
options.style !== Style.Css
) {
const componentSchematicsOptions: JsonObject = {};
if (options.inlineTemplate ?? options.minimal) {
componentSchematicsOptions.inlineTemplate = true;
}
if (options.inlineStyle ?? options.minimal) {
componentSchematicsOptions.inlineStyle = true;
}
if (options.style && options.style !== Style.Css) {
componentSchematicsOptions.style = options.style;
}
schematics['@schematics/angular:component'] = componentSchematicsOptions;
}
if (options.skipTests || options.minimal) {
const schematicsWithTests = [
'class',
'component',
'directive',
'guard',
'interceptor',
'pipe',
'resolver',
'service',
];
schematicsWithTests.forEach((type) => {
if (!(`@schematics/angular:${type}` in schematics)) {
schematics[`@schematics/angular:${type}`] = {};
}
(schematics[`@schematics/angular:${type}`] as JsonObject).skipTests = true;
});
}
if (options.strict) {
if (!('@schematics/angular:application' in schematics)) {
schematics['@schematics/angular:application'] = {};
}
(schematics['@schematics/angular:application'] as JsonObject).strict = true;
}
const sourceRoot = join(normalize(projectRoot), 'src');
let budgets = [];
if (options.strict) {
budgets = [
{
type: 'initial',
maximumWarning: '500kb',
maximumError: '1mb',
},
{
type: 'anyComponentStyle',
maximumWarning: '2kb',
maximumError: '4kb',
},
];
} else {
budgets = [
{
type: 'initial',
maximumWarning: '2mb',
maximumError: '5mb',
},
{
type: 'anyComponentStyle',
maximumWarning: '6kb',
maximumError: '10kb',
},
];
}
const inlineStyleLanguage = options?.style !== Style.Css ? options.style : undefined;
const project = {
root: normalize(projectRoot),
sourceRoot,
projectType: ProjectType.Application,
prefix: options.prefix || 'app',
schematics,
targets: {
build: {
builder: Builders.Browser,
defaultConfiguration: 'production',
options: {
outputPath: `dist/${folderName}`,
index: `${sourceRoot}/index.html`,
main: `${sourceRoot}/main.ts`,
polyfills: `${sourceRoot}/polyfills.ts`,
tsConfig: `${projectRoot}tsconfig.app.json`,
inlineStyleLanguage,
assets: [`${sourceRoot}/favicon.ico`, `${sourceRoot}/assets`],
styles: [`${sourceRoot}/styles.${options.style}`],
scripts: [],
},
configurations: {
production: {
budgets,
fileReplacements: [
{
replace: `${sourceRoot}/environments/environment.ts`,
with: `${sourceRoot}/environments/environment.prod.ts`,
},
],
outputHashing: 'all',
},
development: {
buildOptimizer: false,
optimization: false,
vendorChunk: true,
extractLicenses: false,
sourceMap: true,
namedChunks: true,
},
},
},
serve: {
builder: Builders.DevServer,
defaultConfiguration: 'development',
options: {},
configurations: {
production: {
browserTarget: `${options.name}:build:production`,
},
development: {
browserTarget: `${options.name}:build:development`,
},
},
},
'extract-i18n': {
builder: Builders.ExtractI18n,
options: {
browserTarget: `${options.name}:build`,
},
},
test: options.minimal
? undefined
: {
builder: Builders.Karma,
options: {
main: `${sourceRoot}/test.ts`,
polyfills: `${sourceRoot}/polyfills.ts`,
tsConfig: `${projectRoot}tsconfig.spec.json`,
karmaConfig: `${projectRoot}karma.conf.js`,
inlineStyleLanguage,
assets: [`${sourceRoot}/favicon.ico`, `${sourceRoot}/assets`],
styles: [`${sourceRoot}/styles.${options.style}`],
scripts: [],
},
},
},
};
return updateWorkspace((workspace) => {
if (workspace.projects.size === 0) {
workspace.extensions.defaultProject = options.name;
}
workspace.projects.add({
name: options.name,
...project,
});
});
}