Skip to content

Commit 570da4a

Browse files
authored
Merge pull request #92 from waysact/webpack-assets-manifest
Document webpack-asset-manifest integration
2 parents 27c9b64 + e186f4e commit 570da4a

File tree

6 files changed

+64
-7
lines changed

6 files changed

+64
-7
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ When this value is falsy, the plugin doesn't run and no integrity
123123
values are calculated. It is recommended to disable the plugin in
124124
development mode.
125125

126+
## Exporting `integrity` values
127+
128+
You might want to export generated integrity hashes, perhaps for use
129+
with SSR. We recommend
130+
[webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest)
131+
for this purpose. When configured with option `integrity: true` it
132+
will include the hashes generated by this plugin in the manifest
133+
(requires webpack-assets-manifest version >= 3 which in turn requires
134+
Webpack >= 4.)
135+
136+
[Example usage with webpack-assets-manifest](examples/webpack-assets-manifest/).
137+
126138
## Caveats
127139

128140
### Proxies
@@ -165,12 +177,12 @@ using a tool such as [`http-server`](https://github.com/indexzero/http-server).
165177

166178
### Safari and Assets that Require Cookies
167179

168-
As detailed in [Webpack Issue
169-
#6972](https://github.com/webpack/webpack/issues/6972), the
170-
`crossOrigin` attribute can break loading of assets in certain edge
171-
cases due to a bug in Safari. Since SRI requires the `crossOrigin`
172-
attribute to be set, you may run into this case even when source URL
173-
is same-origin with respect to the asset.
180+
As detailed in
181+
[Webpack Issue #6972](https://github.com/webpack/webpack/issues/6972),
182+
the `crossOrigin` attribute can break loading of assets in certain
183+
edge cases due to a bug in Safari. Since SRI requires the
184+
`crossOrigin` attribute to be set, you may run into this case even
185+
when source URL is same-origin with respect to the asset.
174186

175187
## Further Reading
176188

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Integration with webpack-assets-manifest
2+
3+
[webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest)
4+
has a somewhat
5+
[undocumented feature](https://github.com/webdeveric/webpack-assets-manifest/blob/9261b516209ece4311b77f200b78ff5dc945985f/src/WebpackAssetsManifest.js#L448-L449)
6+
where it will include the `integrity` value generated by this plugin
7+
(by webpack-subresource-integrity) when configured with `integrity: true`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('ok');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var expect = require('expect');
2+
var fs = require('fs');
3+
var path = require('path');
4+
var webpackVersion = Number(
5+
require('webpack/package.json').version.split('.')[0]
6+
);
7+
8+
module.exports.skip = function skip() {
9+
// webpack-assets-manifest 3 requires Webpack 4
10+
return webpackVersion < 4;
11+
};
12+
13+
module.exports.check = function check(stats) {
14+
var manifest = JSON.parse(
15+
fs.readFileSync(path.join(__dirname, 'dist/manifest.json'), 'utf-8')
16+
);
17+
expect(manifest['index.js'].integrity).toMatch(/sha384-.* sha512-.*/);
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var SriPlugin = require('webpack-subresource-integrity');
2+
var WebpackAssetsManifest = require('webpack-assets-manifest');
3+
4+
module.exports = {
5+
entry: {
6+
index: './index.js'
7+
},
8+
output: {
9+
crossOriginLoading: 'anonymous'
10+
},
11+
plugins: [
12+
new SriPlugin({
13+
hashFuncNames: ['sha384', 'sha512'],
14+
enabled: true
15+
}),
16+
new WebpackAssetsManifest({ integrity: true })
17+
]
18+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"soupselect": "^0.2.0",
7272
"style-loader": "^0.18.0",
7373
"tmp": "^0.0.31",
74-
"webpack": "^1.12.11"
74+
"webpack": "^1.12.11",
75+
"webpack-assets-manifest": "^3.0.0"
7576
},
7677
"peerDependencies": {
7778
"html-webpack-plugin": "^2.21.0 || ~3 || >=4.0.0-alpha.2 <5",

0 commit comments

Comments
 (0)