Skip to content
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

Webpack 5 support #130

Merged
merged 26 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5dd739e
Webpack 5 compatibility
jscheid Dec 6, 2019
9fc191f
Fix CI
jscheid Dec 6, 2019
1875c0b
Declare compatibility with Webpack 5.0.0 beta
jscheid Dec 6, 2019
6fb9390
More CI fixes
jscheid Dec 6, 2019
a76916a
Run with latest html-webpack-plugin beta
jscheid Dec 6, 2019
be5a5eb
Fix webpack dependency spec
jscheid Dec 6, 2019
25c785c
Fix Appveyor configuration
jscheid Dec 8, 2019
ee4974e
Compatibility with webpack@5.0.0-beta20
jscheid Jul 4, 2020
90c1377
Fix travis.yml
jscheid Jul 4, 2020
aaeaf56
Another fix for travis.yml
jscheid Jul 5, 2020
c2de3da
Support for LoadScriptRuntimeModule
jscheid Jul 5, 2020
44f124e
Test against latest html-webpack-plugin@4
jscheid Jul 5, 2020
ab9b84a
Exclude webpack@next on Node 8 from testing
jscheid Jul 5, 2020
fb72eee
Compatibility with webpack@5.0.0-beta28
jscheid Aug 23, 2020
db7f85d
Fixate compatible Webpack version
jscheid Aug 23, 2020
cf4c60c
Run Appveyor against latest Webpack beta
jscheid Aug 24, 2020
f984771
Fix Appveyor build
jscheid Aug 24, 2020
b9949ab
Fix npm cache clean invocation
jscheid Aug 24, 2020
c84e17a
Another attempt at fixing Appveyor failure
jscheid Sep 15, 2020
5f55211
Stop testing Node 4 on Windows
jscheid Oct 9, 2020
878afff
Test against Webpack 5
jscheid Oct 11, 2020
695be87
Fix Webpack 5 deprecation warning
jscheid Oct 11, 2020
9c5ca81
Fix Travis exclusions
jscheid Oct 11, 2020
3cc27aa
Bump version to 1.5.0
jscheid Oct 11, 2020
00dd2bc
Refactor hook setup
jscheid Oct 12, 2020
1631ca6
Clean up dependency version ranges
jscheid Oct 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions .travis.yml
Expand Up @@ -4,20 +4,28 @@ node_js:
- 6
- 8
- 10
- 12
addons:
firefox: latest
env:
- WEBPACK_SUFFIX="@1" ETWP_SUFFIX="@1" HWP_SUFFIX="@2"
- WEBPACK_SUFFIX="@2" ETWP_SUFFIX="@2" HWP_SUFFIX="@2"
- WEBPACK_SUFFIX="@3" ETWP_SUFFIX="@3" HWP_SUFFIX="@2"
- WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@3"
- WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4.0.0-alpha.2"
- WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
- WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
matrix:
exclude:
- node_js: 4
env: WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@3"
- node_js: 4
env: WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4.0.0-alpha.2"
env: WEBPACK_SUFFIX="@4" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
- node_js: 4
env: WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
- node_js: 6
env: WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
- node_js: 8
env: WEBPACK_SUFFIX="@5" ETWP_SUFFIX="@4.0.0-alpha.0" HWP_SUFFIX="@4"
install:
- npm install || true
- npm rm webpack extract-text-webpack-plugin eslint
Expand All @@ -29,7 +37,6 @@ before_script:
services:
- xvfb
script:
- ./node_modules/karma/bin/karma start --single-run --browsers Firefox
- $(npm bin)/nyc $(npm bin)/mocha --exit --timeout 20000 && $(npm bin)/nyc report --reporter=text-lcov | $(npm bin)/coveralls
notifications:
webhooks:
Expand Down
18 changes: 12 additions & 6 deletions README.md
Expand Up @@ -11,16 +11,20 @@ manipulation.

## Features

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

## Installation

```shell
npm install webpack-subresource-integrity --save-dev
```

```shell
yarn add --dev webpack-subresource-integrity
```

### Webpack Configuration Example

```javascript
Expand Down Expand Up @@ -81,9 +85,11 @@ template as follows:
#### Without HtmlWebpackPlugin

The correct value for the `integrity` attribute can be retrieved from
the `integrity` property of Webpack assets. However, that property is
not copied over by Webpack's `stats` module so you'll have to access
the "original" asset on the `compilation` object. For example:
the `integrity` property of Webpack assets.

Note that with Webpack versions before 5, that property is not copied over by
Webpack's `stats` module so you'll have to access the "original" asset on the
`compilation` object. For example:

```javascript
compiler.plugin("done", stats => {
Expand Down
61 changes: 41 additions & 20 deletions appveyor.yml
@@ -1,21 +1,6 @@
# Test against this version of Node.js
environment:
matrix:
- nodejs_version: 4
WEBPACK_SUFFIX: '@1'
ETWP_SUFFIX: '@1'
FL_SUFFIX: '@0'
HWP_SUFFIX: '@2'
- nodejs_version: 4
WEBPACK_SUFFIX: '@2'
ETWP_SUFFIX: '@2'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@2'
- nodejs_version: 4
WEBPACK_SUFFIX: '@3'
ETWP_SUFFIX: '@3'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@2'
- nodejs_version: 6
WEBPACK_SUFFIX: '@1'
ETWP_SUFFIX: '@1'
Expand All @@ -40,7 +25,7 @@ environment:
WEBPACK_SUFFIX: '@4'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@4.0.0-alpha.2'
HWP_SUFFIX: '@4'
- nodejs_version: 8
WEBPACK_SUFFIX: '@1'
ETWP_SUFFIX: '@1'
Expand All @@ -65,7 +50,7 @@ environment:
WEBPACK_SUFFIX: '@4'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@4.0.0-alpha.2'
HWP_SUFFIX: '@4'
- nodejs_version: 10
WEBPACK_SUFFIX: '@1'
ETWP_SUFFIX: '@1'
Expand All @@ -90,14 +75,50 @@ environment:
WEBPACK_SUFFIX: '@4'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@4.0.0-alpha.2'
HWP_SUFFIX: '@4'
- nodejs_version: 10
WEBPACK_SUFFIX: '@5'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@4'
- nodejs_version: 12
WEBPACK_SUFFIX: '@1'
ETWP_SUFFIX: '@1'
FL_SUFFIX: '@0'
HWP_SUFFIX: '@2'
- nodejs_version: 12
WEBPACK_SUFFIX: '@2'
ETWP_SUFFIX: '@2'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@2'
- nodejs_version: 12
WEBPACK_SUFFIX: '@3'
ETWP_SUFFIX: '@3'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@2'
- nodejs_version: 12
WEBPACK_SUFFIX: '@4'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@3'
- nodejs_version: 12
WEBPACK_SUFFIX: '@4'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@4'
- nodejs_version: 12
WEBPACK_SUFFIX: '@5'
ETWP_SUFFIX: '@4.0.0-alpha.0'
FL_SUFFIX: '@1'
HWP_SUFFIX: '@4'

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- appveyor-retry npm install --global npm@3
- npm cache clean --force
- appveyor-retry npm install --global npm@6
- npm install || true
- npm rm webpack extract-text-webpack-plugin file-loader eslint
- npm install "webpack%WEBPACK_SUFFIX%" --ignore-scripts --loglevel=error || true
Expand All @@ -111,7 +132,7 @@ test_script:
- node --version
- npm --version
# run tests
- npm run mocha
- npm run test

# Don't actually build.
build: off
14 changes: 1 addition & 13 deletions examples/disabled/webpack.config.js
@@ -1,21 +1,9 @@
var SriPlugin = require('webpack-subresource-integrity');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var createExtractTextLoader = require('../utils').createExtractTextLoader;
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js'
},
module:
webpackVersion > 1
? { rules: [{ test: /\.css$/, use: createExtractTextLoader() }] }
: { loaders: [{ test: /\.css$/, loader: createExtractTextLoader() }] },
plugins: [
new ExtractTextPlugin('styles.css'),
new SriPlugin({ hashFuncNames: ['sha256'], enabled: false })
]
plugins: [new SriPlugin({ hashFuncNames: ['sha256'], enabled: false })]
};
8 changes: 8 additions & 0 deletions examples/etp-content-hash/test.js
@@ -1,4 +1,12 @@
var expect = require('expect');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
// Can't use extract-text-webpack-plugin with Webpack > 4.
return webpackVersion > 4;
};

module.exports.check = function check(stats) {
expect(stats.compilation.warnings).toEqual([]);
Expand Down
8 changes: 8 additions & 0 deletions examples/etp-path-join/test.js
@@ -1,4 +1,12 @@
var expect = require('expect');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
// Can't use extract-text-webpack-plugin with Webpack > 4.
return webpackVersion > 4;
};

module.exports.check = function check(stats) {
expect(stats.compilation.warnings).toEqual([]);
Expand Down
8 changes: 8 additions & 0 deletions examples/hwp-custom-template/test.js
Expand Up @@ -2,6 +2,14 @@ var select = require('soupselect').select;
var expect = require('expect');
var htmlparser = require('htmlparser');
var fs = require('fs');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
// Can't use extract-text-webpack-plugin with Webpack > 4.
return webpackVersion > 4;
};

module.exports.check = function check(stats) {
var jsIntegrity;
Expand Down
8 changes: 8 additions & 0 deletions examples/hwp-integrity-attributes/test.js
Expand Up @@ -2,6 +2,14 @@ var select = require('soupselect').select;
var expect = require('expect');
var htmlparser = require('htmlparser');
var fs = require('fs');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
// Can't use extract-text-webpack-plugin with Webpack > 4.
return webpackVersion > 4;
};

module.exports.check = function check(stats) {
var jsIntegrity;
Expand Down
5 changes: 4 additions & 1 deletion examples/hwp-output-parent-dir/test.js
Expand Up @@ -7,7 +7,10 @@ module.exports.check = function check(stats) {
var jsIntegrity;

expect(stats.compilation.warnings).toEqual([]);
jsIntegrity = stats.compilation.assets['bundle.js'].integrity;

jsIntegrity =
stats.toJson().assets.find(asset => asset.name === 'bundle.js').integrity ||
stats.compilation.assets['bundle.js'].integrity;
expect(jsIntegrity).toMatch(/^sha/);

return new Promise((resolve, reject) => {
Expand Down
4 changes: 3 additions & 1 deletion examples/hwp-public-path/test.js
Expand Up @@ -7,7 +7,9 @@ module.exports.check = function check(stats) {
var jsIntegrity;

expect(stats.compilation.warnings).toEqual([]);
jsIntegrity = stats.compilation.assets['bundle.js'].integrity;
jsIntegrity =
stats.toJson().assets.find(asset => asset.name === 'bundle.js').integrity ||
stats.compilation.assets['bundle.js'].integrity;
expect(jsIntegrity).toMatch(/^sha/);

return new Promise((resolve, reject) => {
Expand Down
4 changes: 3 additions & 1 deletion examples/hwp-subdirectories/test.js
Expand Up @@ -4,7 +4,9 @@ var htmlparser = require('htmlparser');
var fs = require('fs');

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

return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/mini-css-extract-plugin/test.js
Expand Up @@ -4,5 +4,5 @@ var webpackVersion = Number(

module.exports.skip = function skip() {
// mini-css-extract-plugin needs Webpack 4
return webpackVersion < 4;
return webpackVersion !== 4;
};
8 changes: 8 additions & 0 deletions examples/no-error-invalid-config/test.js
@@ -1,5 +1,13 @@
var expect = require('expect');
var ChunkRenderError = require('webpack/lib/ChunkRenderError');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
// Error doesn't get triggered with Webpack > 4.
return webpackVersion > 4;
};

module.exports.ignoreErrors = true;

Expand Down
1 change: 0 additions & 1 deletion examples/no-error-invalid-config/webpack.config.js
@@ -1,5 +1,4 @@
var SriPlugin = require('webpack-subresource-integrity');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './index.js',
Expand Down
2 changes: 1 addition & 1 deletion examples/sourcemap-code-splitting/test.js
Expand Up @@ -17,6 +17,6 @@ module.exports.check = function check() {
}

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