Skip to content

Commit

Permalink
feat: add support for SRI (integrity) (with webpack-subresource-integ…
Browse files Browse the repository at this point in the history
…rity) (#436)
  • Loading branch information
ashudson23 authored and gregberge committed Sep 25, 2019
1 parent 38ce5f0 commit 586ad0a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ function extraPropsToString(asset, extraProps) {
)
}

function getSriHtmlAttributes(asset) {
if (!asset.integrity) {
return ''
}
return ` integrity="${asset.integrity}"`
}

function assetToScriptTag(asset, extraProps) {
return `<script async data-chunk="${asset.chunk}" src="${
asset.url
}"${extraPropsToString(asset, extraProps)}></script>`
}"${getSriHtmlAttributes(asset)}${extraPropsToString(asset, extraProps)}></script>`
}

function assetToScriptElement(asset, extraProps) {
Expand Down Expand Up @@ -66,7 +73,7 @@ function assetToStyleString(asset, { inputFileSystem }) {
function assetToStyleTag(asset, extraProps) {
return `<link data-chunk="${asset.chunk}" rel="stylesheet" href="${
asset.url
}"${extraPropsToString(asset, extraProps)}>`
}"${getSriHtmlAttributes(asset)}${extraPropsToString(asset, extraProps)}>`
}

function assetToStyleTagInline(asset, extraProps, { inputFileSystem }) {
Expand Down Expand Up @@ -128,7 +135,7 @@ function assetToLinkTag(asset, extraProps) {
const hint = LINK_ASSET_HINTS[asset.type]
return `<link ${hint}="${asset.chunk}" rel="${asset.linkType}" as="${
asset.scriptType
}" href="${asset.url}"${extraPropsToString(asset, extraProps)}>`
}" href="${asset.url}"${getSriHtmlAttributes(asset)}${extraPropsToString(asset, extraProps)}>`
}

function assetToLinkElement(asset, extraProps) {
Expand Down

0 comments on commit 586ad0a

Please sign in to comment.