Skip to content

Commit

Permalink
Document webpack-asset-manifest integration
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
jscheid committed Oct 4, 2018
1 parent 27c9b64 commit 9a9c290
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ When this value is falsy, the plugin doesn't run and no integrity
values are calculated. It is recommended to disable the plugin in
development mode.

## Exporting `integrity` values

You might want to export generated integrity hashes, perhaps for use
with SSR. We recommend
[webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest)
for this purpose. When configured with option `integrity: true` it
will include the hashes generated by this plugin in the manifest
(requires webpack-assets-manifest version >= 3 which in turn requires
Webpack >= 4.)

[Example usage with webpack-assets-manifest](examples/webpack-assets-manifest/).

## Caveats

### Proxies
Expand Down
7 changes: 7 additions & 0 deletions examples/webpack-assets-manifest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Integration with webpack-assets-manifest

[webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest)
has a somewhat
[undocumented feature](https://github.com/webdeveric/webpack-assets-manifest/blob/9261b516209ece4311b77f200b78ff5dc945985f/src/WebpackAssetsManifest.js#L448-L449)
where it will include the `integrity` value generated by this plugin
(by webpack-subresource-integrity) when configured with `integrity: true`.
1 change: 1 addition & 0 deletions examples/webpack-assets-manifest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('ok');
18 changes: 18 additions & 0 deletions examples/webpack-assets-manifest/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var expect = require('expect');
var fs = require('fs');
var path = require('path');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
// webpack-assets-manifest 3 requires Webpack 4
return webpackVersion < 4;
};

module.exports.check = function check(stats) {
var manifest = JSON.parse(
fs.readFileSync(path.join(__dirname, 'dist/manifest.json'), 'utf-8')
);
expect(manifest['index.js'].integrity).toMatch(/sha384-.* sha512-.*/);
};
18 changes: 18 additions & 0 deletions examples/webpack-assets-manifest/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var SriPlugin = require('webpack-subresource-integrity');
var WebpackAssetsManifest = require('webpack-assets-manifest');

module.exports = {
entry: {
index: './index.js'
},
output: {
crossOriginLoading: 'anonymous'
},
plugins: [
new SriPlugin({
hashFuncNames: ['sha384', 'sha512'],
enabled: true
}),
new WebpackAssetsManifest({ integrity: true })
]
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"soupselect": "^0.2.0",
"style-loader": "^0.18.0",
"tmp": "^0.0.31",
"webpack": "^1.12.11"
"webpack": "^1.12.11",
"webpack-assets-manifest": "^3.0.0"
},
"peerDependencies": {
"html-webpack-plugin": "^2.21.0 || ~3 || >=4.0.0-alpha.2 <5",
Expand Down

0 comments on commit 9a9c290

Please sign in to comment.