diff --git a/packages/server/__fixtures__/stats.json b/packages/server/__fixtures__/stats.json
index d75969d3..e1ca016d 100644
--- a/packages/server/__fixtures__/stats.json
+++ b/packages/server/__fixtures__/stats.json
@@ -1,7 +1,7 @@
{
"errors": [],
"warnings": [],
- "hash": "6cacb38ddc45b9bbd140",
+ "hash": "993926e214fb7781ad85",
"publicPath": "/dist/node/",
"outputPath": "../../examples/server-side-rendering/public/dist/node",
"assetsByChunkName": {
diff --git a/packages/server/src/ChunkExtractor.js b/packages/server/src/ChunkExtractor.js
index 80e95f2b..23dc0a31 100644
--- a/packages/server/src/ChunkExtractor.js
+++ b/packages/server/src/ChunkExtractor.js
@@ -79,6 +79,7 @@ function assetToScriptElement(asset, extraProps) {
async
data-chunk={asset.chunk}
src={asset.url}
+ integrity={asset.integrity || undefined}
{...handleExtraProps(asset, extraProps)}
/>
)
@@ -128,6 +129,7 @@ function assetToStyleElement(asset, extraProps) {
data-chunk={asset.chunk}
rel="stylesheet"
href={asset.url}
+ integrity={asset.integrity || undefined}
{...handleExtraProps(asset, extraProps)}
/>
)
@@ -175,6 +177,7 @@ function assetToLinkElement(asset, extraProps) {
rel: asset.linkType,
as: asset.scriptType,
href: asset.url,
+ integrity: asset.integrity || undefined,
...handleExtraProps(asset, extraProps),
}
return
diff --git a/packages/server/src/ChunkExtractor.test.js b/packages/server/src/ChunkExtractor.test.js
index 2551235c..d7aeab37 100644
--- a/packages/server/src/ChunkExtractor.test.js
+++ b/packages/server/src/ChunkExtractor.test.js
@@ -413,6 +413,61 @@ describe('ChunkExtrator', () => {
]
`)
})
+
+ it('should add integrity if available in stats', () => {
+ const testExtractor = new ChunkExtractor({
+ stats: {
+ ...stats,
+ namedChunkGroups: {
+ ...stats.namedChunkGroups,
+ main: {
+ ...stats.namedChunkGroups.main,
+ assets: stats.namedChunkGroups.main.assets.map(name => ({
+ name,
+ // pseudo hash - reversed name
+ integrity: name
+ .split('')
+ .reverse()
+ .join(''),
+ })),
+ },
+ },
+ },
+ outputPath: targetPath,
+ })
+ expect(testExtractor.getScriptElements({ crossorigin: 'anonymous' }))
+ .toMatchInlineSnapshot(`
+ Array [
+ ,
+ ,
+ ,
+ ]
+ `)
+ })
})
describe('#getStyleTags', () => {
@@ -617,6 +672,41 @@ describe('ChunkExtrator', () => {
]
`)
})
+
+ it('should add integrity if available in stats', () => {
+ const testExtractor = new ChunkExtractor({
+ stats: {
+ ...stats,
+ namedChunkGroups: {
+ ...stats.namedChunkGroups,
+ main: {
+ ...stats.namedChunkGroups.main,
+ assets: stats.namedChunkGroups.main.assets.map(name => ({
+ name,
+ // pseudo hash - reversed name
+ integrity: name
+ .split('')
+ .reverse()
+ .join(''),
+ })),
+ },
+ },
+ },
+ outputPath: targetPath,
+ })
+ expect(testExtractor.getStyleElements({ crossorigin: 'anonymous' }))
+ .toMatchInlineSnapshot(`
+ Array [
+ ,
+ ]
+ `)
+ })
})
describe('#getInlineStyleElements', () => {
@@ -921,6 +1011,64 @@ describe('ChunkExtrator', () => {
]
`)
})
+
+ it('should add integrity if available in stats', () => {
+ const testExtractor = new ChunkExtractor({
+ stats: {
+ ...stats,
+ namedChunkGroups: {
+ ...stats.namedChunkGroups,
+ main: {
+ ...stats.namedChunkGroups.main,
+ assets: stats.namedChunkGroups.main.assets.map(name => ({
+ name,
+ // pseudo hash - reversed name
+ integrity: name
+ .split('')
+ .reverse()
+ .join(''),
+ })),
+ },
+ },
+ },
+ outputPath: targetPath,
+ })
+ expect(testExtractor.getLinkElements({ crossorigin: 'anonymous' }))
+ .toMatchInlineSnapshot(`
+ Array [
+ ,
+ ,
+ ,
+ ,
+ ]
+ `)
+ })
})
describe('#requireEntryPoint', () => {