Skip to content

Commit 0d5e53d

Browse files
authored
fix(rspack): make subresourceIntegrity usage configurable (#29629)
## Current Behavior We currently set Subresource Integrity (SRI) on all scripts injected via `HtmlRspackPlugin`. This should be configurable. ## Expected Behavior Expose an option to set SRI - mark false by default to match Rspack's `HtmlRspackPlugin` behaviour
1 parent f24a869 commit 0d5e53d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

packages/rspack/src/plugins/utils/apply-web-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function applyWebConfig(
6969
plugins.push(
7070
new HtmlRspackPlugin({
7171
template: options.index,
72-
sri: 'sha256',
72+
sri: options.subresourceIntegrity ? 'sha256' : undefined,
7373
...(options.baseHref ? { base: { href: options.baseHref } } : {}),
7474
...(config.output?.scriptType === 'module'
7575
? { scriptLoading: 'module' }

packages/rspack/src/plugins/utils/models.ts

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ export interface NxAppRspackPluginOptions {
199199
* External stylesheets that will be included with the application.
200200
*/
201201
styles?: Array<ExtraEntryPointClass | string>;
202+
/**
203+
* Enables the use of subresource integrity validation.
204+
*/
205+
subresourceIntegrity?: boolean;
202206
/**
203207
* Override the `target` option in rspack configuration. This setting is not recommended and exists for backwards compatibility.
204208
*/

packages/rspack/src/plugins/utils/plugins/normalize-options.ts

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export function normalizeOptions(
124124
sourceMap: combinedPluginAndMaybeExecutorOptions.sourceMap ?? !isProd,
125125
sourceRoot,
126126
styles: combinedPluginAndMaybeExecutorOptions.styles ?? [],
127+
subresourceIntegrity:
128+
combinedPluginAndMaybeExecutorOptions.subresourceIntegrity ?? false,
127129
target: combinedPluginAndMaybeExecutorOptions.target ?? 'web',
128130
targetName,
129131
vendorChunk: combinedPluginAndMaybeExecutorOptions.vendorChunk ?? !isProd,

0 commit comments

Comments
 (0)