Skip to content

Commit 1d6bfcd

Browse files
authored
Merge pull request #130 from waysact/webpack-5
Webpack 5 support
2 parents f9d76c0 + 1631ca6 commit 1d6bfcd

File tree

18 files changed

+241
-107
lines changed

18 files changed

+241
-107
lines changed

.travis.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ node_js:
44
- 6
55
- 8
66
- 10
7+
- 12
78
addons:
89
firefox: latest
910
env:
1011
- WEBPACK_SUFFIX="@1" ETWP_SUFFIX="@1" HWP_SUFFIX="@2"
1112
- WEBPACK_SUFFIX="@2" ETWP_SUFFIX="@2" HWP_SUFFIX="@2"
1213
- WEBPACK_SUFFIX="@3" ETWP_SUFFIX="@3" HWP_SUFFIX="@2"
1314
- WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@3"
14-
- WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4.0.0-alpha.2"
15+
- WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
16+
- WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
1517
matrix:
1618
exclude:
1719
- node_js: 4
1820
env: WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@3"
1921
- node_js: 4
20-
env: WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4.0.0-alpha.2"
22+
env: WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
23+
- node_js: 4
24+
env: WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
25+
- node_js: 6
26+
env: WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
27+
- node_js: 8
28+
env: WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
2129
install:
2230
- npm install || true
2331
- npm rm webpack extract-text-webpack-plugin eslint
@@ -29,7 +37,6 @@ before_script:
2937
services:
3038
- xvfb
3139
script:
32-
- ./node_modules/karma/bin/karma start --single-run --browsers Firefox
3340
- $(npm bin)/nyc $(npm bin)/mocha --exit --timeout 20000 && $(npm bin)/nyc report --reporter=text-lcov | $(npm bin)/coveralls
3441
notifications:
3542
webhooks:

README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ manipulation.
1111

1212
## Features
1313

14-
- Optional integration with [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin)
15-
- Automatic support for code splitting (integrity for lazy-loaded chunks)
16-
- Compatible with Webpack 1.x, 2.x, 3.x and 4.x
14+
- Optional integration with [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin).
15+
- Automatic support for dynamic imports (also known as code splitting.)
16+
- Compatible with all major Webpack versions, up to and including Webpack 5.
1717

1818
## Installation
1919

2020
```shell
2121
npm install webpack-subresource-integrity --save-dev
2222
```
2323

24+
```shell
25+
yarn add --dev webpack-subresource-integrity
26+
```
27+
2428
### Webpack Configuration Example
2529

2630
```javascript
@@ -81,9 +85,11 @@ template as follows:
8185
#### Without HtmlWebpackPlugin
8286

8387
The correct value for the `integrity` attribute can be retrieved from
84-
the `integrity` property of Webpack assets. However, that property is
85-
not copied over by Webpack's `stats` module so you'll have to access
86-
the "original" asset on the `compilation` object. For example:
88+
the `integrity` property of Webpack assets.
89+
90+
Note that with Webpack versions before 5, that property is not copied over by
91+
Webpack's `stats` module so you'll have to access the "original" asset on the
92+
`compilation` object. For example:
8793

8894
```javascript
8995
compiler.plugin("done", stats => {

appveyor.yml

+41-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
# Test against this version of Node.js
22
environment:
33
matrix:
4-
- nodejs_version: 4
5-
WEBPACK_SUFFIX: '@1'
6-
ETWP_SUFFIX: '@1'
7-
FL_SUFFIX: '@0'
8-
HWP_SUFFIX: '@2'
9-
- nodejs_version: 4
10-
WEBPACK_SUFFIX: '@2'
11-
ETWP_SUFFIX: '@2'
12-
FL_SUFFIX: '@1'
13-
HWP_SUFFIX: '@2'
14-
- nodejs_version: 4
15-
WEBPACK_SUFFIX: '@3'
16-
ETWP_SUFFIX: '@3'
17-
FL_SUFFIX: '@1'
18-
HWP_SUFFIX: '@2'
194
- nodejs_version: 6
205
WEBPACK_SUFFIX: '@1'
216
ETWP_SUFFIX: '@1'
@@ -40,7 +25,7 @@ environment:
4025
WEBPACK_SUFFIX: '@4'
4126
ETWP_SUFFIX: '@4.0.0-alpha.0'
4227
FL_SUFFIX: '@1'
43-
HWP_SUFFIX: '@4.0.0-alpha.2'
28+
HWP_SUFFIX: '@4'
4429
- nodejs_version: 8
4530
WEBPACK_SUFFIX: '@1'
4631
ETWP_SUFFIX: '@1'
@@ -65,7 +50,7 @@ environment:
6550
WEBPACK_SUFFIX: '@4'
6651
ETWP_SUFFIX: '@4.0.0-alpha.0'
6752
FL_SUFFIX: '@1'
68-
HWP_SUFFIX: '@4.0.0-alpha.2'
53+
HWP_SUFFIX: '@4'
6954
- nodejs_version: 10
7055
WEBPACK_SUFFIX: '@1'
7156
ETWP_SUFFIX: '@1'
@@ -90,14 +75,50 @@ environment:
9075
WEBPACK_SUFFIX: '@4'
9176
ETWP_SUFFIX: '@4.0.0-alpha.0'
9277
FL_SUFFIX: '@1'
93-
HWP_SUFFIX: '@4.0.0-alpha.2'
78+
HWP_SUFFIX: '@4'
79+
- nodejs_version: 10
80+
WEBPACK_SUFFIX: '@5'
81+
ETWP_SUFFIX: '@4.0.0-alpha.0'
82+
FL_SUFFIX: '@1'
83+
HWP_SUFFIX: '@4'
84+
- nodejs_version: 12
85+
WEBPACK_SUFFIX: '@1'
86+
ETWP_SUFFIX: '@1'
87+
FL_SUFFIX: '@0'
88+
HWP_SUFFIX: '@2'
89+
- nodejs_version: 12
90+
WEBPACK_SUFFIX: '@2'
91+
ETWP_SUFFIX: '@2'
92+
FL_SUFFIX: '@1'
93+
HWP_SUFFIX: '@2'
94+
- nodejs_version: 12
95+
WEBPACK_SUFFIX: '@3'
96+
ETWP_SUFFIX: '@3'
97+
FL_SUFFIX: '@1'
98+
HWP_SUFFIX: '@2'
99+
- nodejs_version: 12
100+
WEBPACK_SUFFIX: '@4'
101+
ETWP_SUFFIX: '@4.0.0-alpha.0'
102+
FL_SUFFIX: '@1'
103+
HWP_SUFFIX: '@3'
104+
- nodejs_version: 12
105+
WEBPACK_SUFFIX: '@4'
106+
ETWP_SUFFIX: '@4.0.0-alpha.0'
107+
FL_SUFFIX: '@1'
108+
HWP_SUFFIX: '@4'
109+
- nodejs_version: 12
110+
WEBPACK_SUFFIX: '@5'
111+
ETWP_SUFFIX: '@4.0.0-alpha.0'
112+
FL_SUFFIX: '@1'
113+
HWP_SUFFIX: '@4'
94114

95115
# Install scripts. (runs after repo cloning)
96116
install:
97117
# Get the latest stable version of Node.js or io.js
98118
- ps: Install-Product node $env:nodejs_version
99119
# install modules
100-
- appveyor-retry npm install --global npm@3
120+
- npm cache clean --force
121+
- appveyor-retry npm install --global npm@6
101122
- npm install || true
102123
- npm rm webpack extract-text-webpack-plugin file-loader eslint
103124
- npm install "webpack%WEBPACK_SUFFIX%" --ignore-scripts --loglevel=error || true
@@ -111,7 +132,7 @@ test_script:
111132
- node --version
112133
- npm --version
113134
# run tests
114-
- npm run mocha
135+
- npm run test
115136

116137
# Don't actually build.
117138
build: off

examples/disabled/webpack.config.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
var SriPlugin = require('webpack-subresource-integrity');
2-
var ExtractTextPlugin = require('extract-text-webpack-plugin');
3-
var createExtractTextLoader = require('../utils').createExtractTextLoader;
4-
var webpackVersion = Number(
5-
require('webpack/package.json').version.split('.')[0]
6-
);
72

83
module.exports = {
94
entry: './index.js',
105
output: {
116
filename: 'bundle.js'
127
},
13-
module:
14-
webpackVersion > 1
15-
? { rules: [{ test: /\.css$/, use: createExtractTextLoader() }] }
16-
: { loaders: [{ test: /\.css$/, loader: createExtractTextLoader() }] },
17-
plugins: [
18-
new ExtractTextPlugin('styles.css'),
19-
new SriPlugin({ hashFuncNames: ['sha256'], enabled: false })
20-
]
8+
plugins: [new SriPlugin({ hashFuncNames: ['sha256'], enabled: false })]
219
};

examples/etp-content-hash/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
var expect = require('expect');
2+
var webpackVersion = Number(
3+
require('webpack/package.json').version.split('.')[0]
4+
);
5+
6+
module.exports.skip = function skip() {
7+
// Can't use extract-text-webpack-plugin with Webpack > 4.
8+
return webpackVersion > 4;
9+
};
210

311
module.exports.check = function check(stats) {
412
expect(stats.compilation.warnings).toEqual([]);

examples/etp-path-join/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
var expect = require('expect');
2+
var webpackVersion = Number(
3+
require('webpack/package.json').version.split('.')[0]
4+
);
5+
6+
module.exports.skip = function skip() {
7+
// Can't use extract-text-webpack-plugin with Webpack > 4.
8+
return webpackVersion > 4;
9+
};
210

311
module.exports.check = function check(stats) {
412
expect(stats.compilation.warnings).toEqual([]);

examples/hwp-custom-template/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ var select = require('soupselect').select;
22
var expect = require('expect');
33
var htmlparser = require('htmlparser');
44
var fs = require('fs');
5+
var webpackVersion = Number(
6+
require('webpack/package.json').version.split('.')[0]
7+
);
8+
9+
module.exports.skip = function skip() {
10+
// Can't use extract-text-webpack-plugin with Webpack > 4.
11+
return webpackVersion > 4;
12+
};
513

614
module.exports.check = function check(stats) {
715
var jsIntegrity;

examples/hwp-integrity-attributes/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ var select = require('soupselect').select;
22
var expect = require('expect');
33
var htmlparser = require('htmlparser');
44
var fs = require('fs');
5+
var webpackVersion = Number(
6+
require('webpack/package.json').version.split('.')[0]
7+
);
8+
9+
module.exports.skip = function skip() {
10+
// Can't use extract-text-webpack-plugin with Webpack > 4.
11+
return webpackVersion > 4;
12+
};
513

614
module.exports.check = function check(stats) {
715
var jsIntegrity;

examples/hwp-output-parent-dir/test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ module.exports.check = function check(stats) {
77
var jsIntegrity;
88

99
expect(stats.compilation.warnings).toEqual([]);
10-
jsIntegrity = stats.compilation.assets['bundle.js'].integrity;
10+
11+
jsIntegrity =
12+
stats.toJson().assets.find(asset => asset.name === 'bundle.js').integrity ||
13+
stats.compilation.assets['bundle.js'].integrity;
1114
expect(jsIntegrity).toMatch(/^sha/);
1215

1316
return new Promise((resolve, reject) => {

examples/hwp-public-path/test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports.check = function check(stats) {
77
var jsIntegrity;
88

99
expect(stats.compilation.warnings).toEqual([]);
10-
jsIntegrity = stats.compilation.assets['bundle.js'].integrity;
10+
jsIntegrity =
11+
stats.toJson().assets.find(asset => asset.name === 'bundle.js').integrity ||
12+
stats.compilation.assets['bundle.js'].integrity;
1113
expect(jsIntegrity).toMatch(/^sha/);
1214

1315
return new Promise((resolve, reject) => {

examples/hwp-subdirectories/test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ var htmlparser = require('htmlparser');
44
var fs = require('fs');
55

66
module.exports.check = function check(stats) {
7-
var jsIntegrity = stats.compilation.assets['subdir/bundle.js'].integrity;
7+
var jsIntegrity =
8+
stats.toJson().assets.find(asset => asset.name === 'subdir/bundle.js')
9+
.integrity || stats.compilation.assets['subdir/bundle.js'].integrity;
810
expect(jsIntegrity).toMatch(/^sha/);
911

1012
return new Promise((resolve, reject) => {

examples/mini-css-extract-plugin/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ var webpackVersion = Number(
44

55
module.exports.skip = function skip() {
66
// mini-css-extract-plugin needs Webpack 4
7-
return webpackVersion < 4;
7+
return webpackVersion !== 4;
88
};

examples/no-error-invalid-config/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
var expect = require('expect');
22
var ChunkRenderError = require('webpack/lib/ChunkRenderError');
3+
var webpackVersion = Number(
4+
require('webpack/package.json').version.split('.')[0]
5+
);
6+
7+
module.exports.skip = function skip() {
8+
// Error doesn't get triggered with Webpack > 4.
9+
return webpackVersion > 4;
10+
};
311

412
module.exports.ignoreErrors = true;
513

examples/no-error-invalid-config/webpack.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var SriPlugin = require('webpack-subresource-integrity');
2-
var HtmlWebpackPlugin = require('html-webpack-plugin');
32

43
module.exports = {
54
entry: './index.js',

examples/sourcemap-code-splitting/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ module.exports.check = function check() {
1717
}
1818

1919
var sriHashesInSource = findAndStripSriHashString('dist/index.js', 'sha256-', -10);
20-
var sriHashesInMap = findAndStripSriHashString('dist/index.js.map', 'var sriHashes = ');
20+
var sriHashesInMap = findAndStripSriHashString('dist/index.js.map', '__webpack_require__.sriHashes = ');
2121
expect(sriHashesInSource.length).toEqual(sriHashesInMap.length);
2222
};

0 commit comments

Comments
 (0)