Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions e2e/cases/output/manifest-integrity/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, getFileContent, rspackTest } from '@e2e/helper';
import type { ManifestData } from '@rsbuild/core';

rspackTest(
'should generate manifest file with integrity in build',
async ({ build }) => {
const rsbuild = await build();
const files = rsbuild.getDistFiles();
const manifestContent = getFileContent(files, 'manifest.json');
const manifest = JSON.parse(manifestContent) as ManifestData;
manifest.allFiles.forEach((item) => {
if (item.endsWith('.js')) {
expect(manifest.integrity[item]).toBeTruthy();
}
});
},
);

rspackTest(
'should generate manifest file with integrity in dev',
async ({ dev }) => {
const rsbuild = await dev();
const files = rsbuild.getDistFiles();
const manifestContent = getFileContent(files, 'manifest.json');
const manifest = JSON.parse(manifestContent) as ManifestData;
manifest.allFiles.forEach((item) => {
if (item.endsWith('.js')) {
expect(manifest.integrity[item]).toBeTruthy();
}
});
},
);
13 changes: 13 additions & 0 deletions e2e/cases/output/manifest-integrity/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
output: {
manifest: true,
filenameHash: false,
},
security: {
sri: {
enable: true,
},
},
});
3 changes: 3 additions & 0 deletions e2e/cases/output/manifest-integrity/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

console.log('hello!', React);
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"reduce-configs": "^1.1.1",
"rslog": "^1.3.0",
"rspack-chain": "^1.4.1",
"rspack-manifest-plugin": "5.1.0",
"rspack-manifest-plugin": "5.2.0",
"sirv": "^3.0.2",
"stacktrace-parser": "^0.1.11",
"style-loader": "3.3.4",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ const generateManifest =
const chunkEntries = new Map<string, FileDescriptor[]>();
const licenseMap = new Map<string, string>();
const publicPath = getPublicPathFromCompiler(compilation);
const integrity: Record<string, string> = {};

const allFiles = files.map((file) => {
if (file.integrity) {
integrity[file.path] = file.integrity;
}

if (file.chunk) {
const entryNames = recursiveChunkEntryNames(file.chunk);

Expand Down Expand Up @@ -144,6 +149,7 @@ const generateManifest =
const manifestData: ManifestData = {
allFiles,
entries: manifestEntries,
integrity,
};

if (manifestOptions.generate) {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,12 @@ export type ManifestData = {
entries: {
[entryName: string]: ManifestByEntry;
};
/**
* Subresource Integrity (SRI) hashes for emitted assets.
* The key is the asset file path, and the value is its integrity hash.
* This field is available only when the `security.sri` option is enabled.
*/
integrity: Record<string, string>;
};

export type ManifestObjectConfig = {
Expand Down
11 changes: 5 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions website/docs/en/config/output/manifest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ type ManifestList = {
*/
assets?: FilePath[];
};
/**
* Subresource Integrity (SRI) hashes for emitted assets.
* The key is the asset file path, and the value is its integrity hash.
* This field is available only when the `security.sri` option is enabled.
*/
integrity: Record<string, string>;
};
};
```
Expand Down
6 changes: 6 additions & 0 deletions website/docs/zh/config/output/manifest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ type ManifestList = {
*/
assets?: FilePath[];
};
/**
* 所有产物文件的子资源完整性(SRI)哈希值
* key 为文件路径,value 为对应的完整性哈希
* 仅在启用 `security.sri` 选项时才会生成该字段
*/
integrity: Record<string, string>;
};
};
```
Expand Down
Loading