Skip to content

Commit 7551f76

Browse files
committed
hardcode transformations in the build tool
1 parent e7e43d6 commit 7551f76

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/angular/build/src/tools/esbuild/index-html-generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export async function generateIndexHtml(
9494
buildOptions.prerenderOptions ||
9595
buildOptions.appShellOptions
9696
),
97+
autoCsp: true,
9798
});
9899

99100
indexHtmlGenerator.readAsset = readAsset;

packages/angular/build/src/utils/index-file/index-html-generator.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { InlineCriticalCssProcessor } from './inline-critical-css';
1616
import { InlineFontsProcessor } from './inline-fonts';
1717
import { addNgcmAttribute } from './ngcm-attribute';
1818
import { addNonce } from './nonce';
19+
import { autoCsp } from './auto-csp';
1920

2021
type IndexHtmlGeneratorPlugin = (
2122
html: string,
@@ -43,6 +44,7 @@ export interface IndexHtmlGeneratorOptions {
4344
cache?: NormalizedCachedOptions;
4445
imageDomains?: string[];
4546
generateDedicatedSSRContent?: boolean;
47+
autoCsp?: boolean;
4648
}
4749

4850
export type IndexHtmlTransform = (content: string) => Promise<string>;
@@ -86,6 +88,11 @@ export class IndexHtmlGenerator {
8688
this.csrPlugins.push(addNgcmAttributePlugin());
8789
this.ssrPlugins.push(addEventDispatchContractPlugin(), addNoncePlugin());
8890
}
91+
92+
// Auto-CSP (as the last step)
93+
if (options.autoCsp) {
94+
this.csrPlugins.push(autoCspPlugin());
95+
}
8996
}
9097

9198
async process(options: IndexHtmlGeneratorProcessOptions): Promise<IndexHtmlProcessResult> {
@@ -198,6 +205,10 @@ function addNoncePlugin(): IndexHtmlGeneratorPlugin {
198205
return (html) => addNonce(html);
199206
}
200207

208+
function autoCspPlugin(): IndexHtmlGeneratorPlugin {
209+
return (html) => autoCsp(html);
210+
}
211+
201212
function postTransformPlugin({ options }: IndexHtmlGenerator): IndexHtmlGeneratorPlugin {
202213
return async (html) => (options.postTransform ? options.postTransform(html) : html);
203214
}

0 commit comments

Comments
 (0)