-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
716 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This is a webpack plugin to expose the data generated by SriPlugin. | ||
// See webpack.prod.config.babel.js | ||
import fs from 'fs'; | ||
|
||
import { oneLine } from 'common-tags'; | ||
|
||
export default class SriDataPlugin { | ||
constructor({ saveAs } = {}) { | ||
if (!saveAs) { | ||
throw new Error('The saveAs parameter cannot be empty'); | ||
} | ||
this.saveAs = saveAs; | ||
} | ||
|
||
apply(compiler) { | ||
compiler.plugin('done', (stats) => { | ||
const sriStats = {}; | ||
try { | ||
Object.keys(stats.compilation.assets).forEach((baseName) => { | ||
const asset = stats.compilation.assets[baseName]; | ||
if (!asset.integrity) { | ||
throw new Error( | ||
oneLine`The integrity property is falsey for | ||
asset ${baseName}; Is the webpack-subresource-integrity | ||
plugin installed and enabled?`); | ||
} | ||
sriStats[baseName] = asset.integrity; | ||
}); | ||
|
||
fs.writeFileSync(this.saveAs, JSON.stringify(sriStats)); | ||
} catch (error) { | ||
stats.compilation.errors.push(error); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.