Skip to content

Commit 903a56e

Browse files
fix: support webpack@5 (#477)
1 parent 4498ed0 commit 903a56e

File tree

23 files changed

+282
-132
lines changed

23 files changed

+282
-132
lines changed

azure-pipelines.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jobs:
5656
node-10-canary:
5757
node_version: ^10.13.0
5858
webpack_version: next
59-
continue_on_error: true
6059
steps:
6160
- task: NodeTool@0
6261
inputs:
@@ -78,7 +77,7 @@ jobs:
7877
displayName: 'Install dependencies'
7978
- script: npm i webpack@$(webpack_version)
8079
displayName: 'Install "webpack@$(webpack_version)"'
81-
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
80+
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit"
8281
displayName: 'Run tests with coverage'
8382
- task: PublishTestResults@2
8483
inputs:
@@ -114,7 +113,6 @@ jobs:
114113
node-10-canary:
115114
node_version: ^10.13.0
116115
webpack_version: next
117-
continue_on_error: true
118116
steps:
119117
- task: NodeTool@0
120118
inputs:
@@ -136,7 +134,7 @@ jobs:
136134
displayName: 'Install dependencies'
137135
- script: npm i webpack@$(webpack_version)
138136
displayName: 'Install "webpack@$(webpack_version)"'
139-
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
137+
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit"
140138
displayName: 'Run tests with coverage'
141139
- task: PublishTestResults@2
142140
inputs:
@@ -172,7 +170,6 @@ jobs:
172170
node-10-canary:
173171
node_version: ^10.13.0
174172
webpack_version: next
175-
continue_on_error: true
176173
steps:
177174
- script: 'git config --global core.autocrlf input'
178175
displayName: 'Config git core.autocrlf'
@@ -197,7 +194,7 @@ jobs:
197194
displayName: 'Install dependencies'
198195
- script: npm i webpack@$(webpack_version)
199196
displayName: 'Install "webpack@$(webpack_version)"'
200-
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
197+
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit"
201198
displayName: 'Run tests with coverage'
202199
- task: PublishTestResults@2
203200
inputs:

package-lock.json

+208-118
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"dist"
3737
],
3838
"peerDependencies": {
39-
"webpack": "^4.4.0"
39+
"webpack": "^4.4.0 || ^5.0.0"
4040
},
4141
"dependencies": {
4242
"loader-utils": "^1.1.0",
@@ -72,7 +72,7 @@
7272
"npm-run-all": "^4.1.5",
7373
"prettier": "^1.19.1",
7474
"standard-version": "^7.0.1",
75-
"webpack": "^4.41.3",
75+
"webpack": "^4.41.4",
7676
"webpack-cli": "^3.3.6",
7777
"webpack-dev-server": "^3.7.2"
7878
},

test/TestCases.test.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ function compareDirectory(actual, expected) {
2626
}
2727

2828
function compareWarning(actual, expectedFile) {
29-
if (!fs.existsSync(expectedFile)) return;
29+
if (!fs.existsSync(expectedFile)) {
30+
return;
31+
}
32+
33+
// eslint-disable-next-line global-require, import/no-dynamic-require
34+
const expected = require(expectedFile);
3035

31-
const expected = require(expectedFile); // eslint-disable-line global-require,import/no-dynamic-require
32-
expect(actual).toBe(expected);
36+
expect(actual.trim()).toBe(expected.trim());
3337
}
3438

3539
describe('TestCases', () => {
@@ -97,8 +101,19 @@ describe('TestCases', () => {
97101
}
98102

99103
const expectedDirectory = path.resolve(directoryForCase, 'expected');
104+
const expectedDirectoryByVersion = path.join(
105+
expectedDirectory,
106+
`webpack-${webpack.version[0]}`
107+
);
100108

101-
compareDirectory(outputDirectoryForCase, expectedDirectory);
109+
if (fs.existsSync(expectedDirectoryByVersion)) {
110+
compareDirectory(
111+
outputDirectoryForCase,
112+
expectedDirectoryByVersion
113+
);
114+
} else {
115+
compareDirectory(outputDirectoryForCase, expectedDirectory);
116+
}
102117

103118
const expectedWarning = path.resolve(directoryForCase, 'warnings.js');
104119
const actualWarning = stats.toString({

test/cases/composes-async/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
/* eslint-disable-next-line no-unused-expressions */
12
import(/* webpackChunkName: "async-1" */ './async-1.css');
3+
/* eslint-disable-next-line no-unused-expressions */
24
import(/* webpackChunkName: "async-2" */ './async-2.css');
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@import url(https://some/other/external/css);
2+
@import url(https://some/external/css);
3+
body {
4+
background: red;
5+
}
6+
7+
.c {
8+
background: red;
9+
}
10+
11+
.c {
12+
color: yellow;
13+
}
14+
15+
.b {
16+
background: red;
17+
}
18+
19+
.b {
20+
color: yellow;
21+
}
22+
23+
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/******/ (() => { // webpackBootstrap
2+
/******/ /************************************************************************/
3+
// extracted by mini-css-extract-plugin
4+
if(false) { var cssReload; }
5+
6+
/******/ })()
7+
;

test/cases/js-hash/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* eslint-disable-next-line no-unused-expressions */
12
import(/* webpackChunkName: "style" */ './style.css');

test/cases/js-hash/webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ module.exports = [1, 2].map((n) => {
3232
],
3333
},
3434
output: {
35-
filename: `[name].[contenthash].js`,
35+
filename: `[name].[contenthash].${n}.js`,
3636
},
3737
plugins: [
3838
new Self({
39-
filename: `[name].[chunkhash].css`,
39+
filename: `[name].[contenthash].${n}.css`,
4040
}),
4141
],
4242
};
+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import './a.css';
22
import './b.css';
33

4+
/* eslint-disable-next-line no-unused-expressions */
45
import(/* webpackChunkName: 'async-one' */ './async-one');
+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import './b.css';
22
import './a.css';
33

4+
/* eslint-disable-next-line no-unused-expressions */
45
import(/* webpackChunkName: 'async-two' */ './async-two');

test/cases/shared-import/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import './a.css';
22
import './b.css';
33

4+
/* eslint-disable-next-line no-unused-expressions */
45
import('./c.css');
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import './a.css';
22
import './b.css';
33

4+
/* eslint-disable-next-line no-unused-expressions */
45
import(/* webpackChunkName: 'async-one' */ './async-one');
6+
/* eslint-disable-next-line no-unused-expressions */
57
import(/* webpackChunkName: 'async-two' */ './async-two');
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import './a.css';
22
import './b.css';
33

4+
/* eslint-disable-next-line no-unused-expressions */
45
import(/* webpackChunkName: 'async-one' */ './async-one');
6+
/* eslint-disable-next-line no-unused-expressions */
57
import(/* webpackChunkName: 'async-two' */ './async-two');
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import './main.css';
22

3+
/* eslint-disable-next-line no-unused-expressions */
34
import('./async');
45

6+
/* eslint-disable-next-line no-unused-expressions */
57
import('./async.css');

test/cases/simple-async/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import './main.css';
22

3+
/* eslint-disable-next-line no-unused-expressions */
34
import('./async');
45

6+
/* eslint-disable-next-line no-unused-expressions */
57
import('./async.css');

test/cases/split-chunks-single/entry1.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ import './e1.css';
33
import './e2.css';
44
import './f.css';
55

6+
/* eslint-disable-next-line no-unused-expressions */
67
import('./chunk1');
8+
/* eslint-disable-next-line no-unused-expressions */
79
import('./chunk2');

test/cases/split-chunks/webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
chunks: 'all',
1616
cacheGroups: {
1717
vendors: {
18+
name: 'vendors',
1819
test: /node_modules/,
1920
enforce: true,
2021
},

0 commit comments

Comments
 (0)