-
-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept additional attributes for assets to support SRI #436
Changes from 1 commit
de507f8
d521fa0
aa31056
b0562e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,19 @@ const mkdirp = require('mkdirp') | |
|
||
class LoadablePlugin { | ||
constructor({ | ||
additionalAssetAttributes = [], | ||
filename = 'loadable-stats.json', | ||
path, | ||
writeToDisk, | ||
outputAsset = true, | ||
} = {}) { | ||
this.opts = { filename, writeToDisk, outputAsset, path } | ||
this.opts = { | ||
additionalAssetAttributes, | ||
filename, | ||
writeToDisk, | ||
outputAsset, | ||
path, | ||
} | ||
|
||
// The Webpack compiler instance | ||
this.compiler = null | ||
|
@@ -26,6 +33,24 @@ class LoadablePlugin { | |
errorDetails: false, | ||
timings: false, | ||
}) | ||
|
||
// include extra asset keys if present | ||
stats.assets = stats.assets.map((asset) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we will be fine without that isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, you're absolute right! I was forcing |
||
const assetAttributes = hookCompiler.assets[asset.name]; | ||
|
||
const validAssetAttributes = Object.keys(assetAttributes) | ||
.filter(key => this.opts.additionalAssetAttributes.includes(key)) | ||
.reduce((obj, key) => { | ||
obj[key] = assetAttributes[key]; | ||
return obj; | ||
}, {}); | ||
|
||
return ({ | ||
...asset, | ||
...validAssetAttributes, | ||
}) | ||
}) | ||
|
||
const result = JSON.stringify(stats, null, 2) | ||
|
||
if (this.opts.outputAsset) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these is useless, the integrity should already be in asset. The only needed part is : getSriHtmlAttributes and all usage of it.