diff --git a/schematics/application/index.spec.ts b/schematics/application/index.spec.ts index 09ce8dbf38..8137c9f094 100644 --- a/schematics/application/index.spec.ts +++ b/schematics/application/index.spec.ts @@ -27,6 +27,10 @@ describe('NgAlainSchematic: application', () => { expect(json != null).toBe(true); expect(json.recommendations[0]).toBe('cipchk.ng-alain-extension-pack'); }); + it('should be add addFileReplacements', () => { + const angualrJson = tree.readContent('angular.json'); + expect(angualrJson).toContain(`fileReplacements`); + }); }); describe('#i18n', () => { diff --git a/schematics/application/index.ts b/schematics/application/index.ts index 9cecc14755..c29d7ff5a6 100644 --- a/schematics/application/index.ts +++ b/schematics/application/index.ts @@ -22,6 +22,7 @@ import { addAllowedCommonJsDependencies, addAllowSyntheticDefaultImports, addAssetsToTarget, + addFileReplacements, addHeadStyle, addHtmlToBody, addPackage, @@ -94,6 +95,7 @@ function fixAngularJson(options: ApplicationOptions): Rule { addStylePreprocessorOptionsToAllProject(workspace); addSchematicCollections(workspace); + addFileReplacements(workspace); }); } diff --git a/schematics/utils/workspace.ts b/schematics/utils/workspace.ts index 9619ef451a..093cc883f7 100644 --- a/schematics/utils/workspace.ts +++ b/schematics/utils/workspace.ts @@ -179,3 +179,18 @@ export function addSchematicCollections(workspace: WorkspaceDefinition): void { if (!schematicCollections.includes(`ng-alain`)) schematicCollections.push(`ng-alain`); workspace.extensions.cli['schematicCollections'] = schematicCollections; } + +export function addFileReplacements(workspace: WorkspaceDefinition): void { + workspace.projects.forEach(project => { + const build = project.targets.get(BUILD_TARGET_BUILD); + if (build == null || build.options == null) return; + if (build.configurations == null) build.configurations = {}; + if (build.configurations.production == null) build.configurations.production = {}; + if (!Array.isArray(build.configurations.production.fileReplacements)) + build.configurations.production.fileReplacements = []; + build.configurations.production.fileReplacements.push({ + replace: 'src/environments/environment.ts', + with: 'src/environments/environment.prod.ts' + }); + }); +}