diff --git a/docs/angular/api-web/executors/build.md b/docs/angular/api-web/executors/build.md index 8673e374c2..2b28fd9e92 100644 --- a/docs/angular/api-web/executors/build.md +++ b/docs/angular/api-web/executors/build.md @@ -48,6 +48,14 @@ Type: `string` The crossorigin attribute to use for generated javascript script tags. One of 'none' | 'anonymous' | 'use-credentials' +### deleteOutputPath + +Default: `true` + +Type: `boolean` + +Delete the output path before building. + ### deployUrl Type: `string` diff --git a/docs/angular/api-web/executors/package.md b/docs/angular/api-web/executors/package.md index 7ce36d29e6..fd09f76f67 100644 --- a/docs/angular/api-web/executors/package.md +++ b/docs/angular/api-web/executors/package.md @@ -28,6 +28,14 @@ Possible values: `dependencies`, `peerDependencies` When updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either `peerDependencies` or `dependencies` +### deleteOutputPath + +Default: `true` + +Type: `boolean` + +Delete the output path before building. + ### entryFile Type: `string` diff --git a/docs/node/api-web/executors/build.md b/docs/node/api-web/executors/build.md index afd96d70bd..8b91449f53 100644 --- a/docs/node/api-web/executors/build.md +++ b/docs/node/api-web/executors/build.md @@ -49,6 +49,14 @@ Type: `string` The crossorigin attribute to use for generated javascript script tags. One of 'none' | 'anonymous' | 'use-credentials' +### deleteOutputPath + +Default: `true` + +Type: `boolean` + +Delete the output path before building. + ### deployUrl Type: `string` diff --git a/docs/node/api-web/executors/package.md b/docs/node/api-web/executors/package.md index 3ada566097..c7a6d77163 100644 --- a/docs/node/api-web/executors/package.md +++ b/docs/node/api-web/executors/package.md @@ -29,6 +29,14 @@ Possible values: `dependencies`, `peerDependencies` When updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either `peerDependencies` or `dependencies` +### deleteOutputPath + +Default: `true` + +Type: `boolean` + +Delete the output path before building. + ### entryFile Type: `string` diff --git a/docs/react/api-web/executors/build.md b/docs/react/api-web/executors/build.md index b4a5541766..6d8dab3120 100644 --- a/docs/react/api-web/executors/build.md +++ b/docs/react/api-web/executors/build.md @@ -49,6 +49,14 @@ Type: `string` The crossorigin attribute to use for generated javascript script tags. One of 'none' | 'anonymous' | 'use-credentials' +### deleteOutputPath + +Default: `true` + +Type: `boolean` + +Delete the output path before building. + ### deployUrl Type: `string` diff --git a/docs/react/api-web/executors/package.md b/docs/react/api-web/executors/package.md index fd723e671c..300b0f5ac6 100644 --- a/docs/react/api-web/executors/package.md +++ b/docs/react/api-web/executors/package.md @@ -29,6 +29,14 @@ Possible values: `dependencies`, `peerDependencies` When updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either `peerDependencies` or `dependencies` +### deleteOutputPath + +Default: `true` + +Type: `boolean` + +Delete the output path before building. + ### entryFile Type: `string` diff --git a/e2e/web/src/web.test.ts b/e2e/web/src/web.test.ts index dbaf3d5b98..de26d979ae 100644 --- a/e2e/web/src/web.test.ts +++ b/e2e/web/src/web.test.ts @@ -74,6 +74,15 @@ describe('Web Components Applications', () => { `dist/libs/${libName}/_should_remove.txt` ); checkFilesExist(`dist/apps/_should_not_remove.txt`); + + // `delete-output-path` + createFile(`dist/apps/${appName}/_should_keep.txt`); + runCLI(`build ${appName} --delete-output-path=false`); + checkFilesExist(`dist/apps/${appName}/_should_keep.txt`); + + createFile(`dist/libs/${libName}/_should_keep.txt`); + runCLI(`build ${libName} --delete-output-path=false`); + checkFilesExist(`dist/libs/${libName}/_should_keep.txt`); }, 120000); it('should do another build if differential loading is needed', async () => { diff --git a/packages/web/src/builders/build/build.impl.ts b/packages/web/src/builders/build/build.impl.ts index ee641a68b2..8134d7c5b5 100644 --- a/packages/web/src/builders/build/build.impl.ts +++ b/packages/web/src/builders/build/build.impl.ts @@ -56,6 +56,8 @@ export interface WebBuildBuilderOptions extends BuildBuilderOptions { verbose?: boolean; buildLibsFromSource?: boolean; + + deleteOutputPath?: boolean; } export default createBuilder(run); @@ -98,7 +100,9 @@ export function run(options: WebBuildBuilderOptions, context: BuilderContext) { } // Delete output path before bundling - deleteOutputDir(context.workspaceRoot, options.outputPath); + if (options.deleteOutputPath) { + deleteOutputDir(context.workspaceRoot, options.outputPath); + } return from(getSourceRoot(context)) .pipe( diff --git a/packages/web/src/builders/build/schema.json b/packages/web/src/builders/build/schema.json index a63d655bb3..c9b2e65ecb 100644 --- a/packages/web/src/builders/build/schema.json +++ b/packages/web/src/builders/build/schema.json @@ -19,6 +19,11 @@ "type": "string", "description": "The output path of the generated files." }, + "deleteOutputPath": { + "type": "boolean", + "description": "Delete the output path before building.", + "default": true + }, "watch": { "type": "boolean", "description": "Enable re-building when files change.", diff --git a/packages/web/src/builders/package/package.impl.ts b/packages/web/src/builders/package/package.impl.ts index 23579d359c..237287522a 100644 --- a/packages/web/src/builders/package/package.impl.ts +++ b/packages/web/src/builders/package/package.impl.ts @@ -124,7 +124,9 @@ export function run( context.logger.info(`Bundling ${context.target.project}...`); // Delete output path before bundling - deleteOutputDir(context.workspaceRoot, options.outputPath); + if (options.deleteOutputPath) { + deleteOutputDir(context.workspaceRoot, options.outputPath); + } return from(rollupOptions).pipe( concatMap((opts) => diff --git a/packages/web/src/builders/package/schema.json b/packages/web/src/builders/package/schema.json index 2faf5ee7a1..ceb75d2610 100644 --- a/packages/web/src/builders/package/schema.json +++ b/packages/web/src/builders/package/schema.json @@ -15,6 +15,11 @@ "type": "string", "description": "The output path of the generated files." }, + "deleteOutputPath": { + "type": "boolean", + "description": "Delete the output path before building.", + "default": true + }, "tsConfig": { "type": "string", "description": "The path to tsconfig file." diff --git a/packages/web/src/utils/types.ts b/packages/web/src/utils/types.ts index 990b3f349b..0b1c287fda 100644 --- a/packages/web/src/utils/types.ts +++ b/packages/web/src/utils/types.ts @@ -60,6 +60,7 @@ export interface PackageBuilderOptions { updateBuildableProjectDepsInPackageJson?: boolean; buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies'; umdName?: string; + deleteOutputPath?: boolean; } export interface AssetGlobPattern extends JsonObject {