Skip to content

Commit 831f771

Browse files
fix: order of @import with pathinfo (#815)
1 parent 58637ca commit 831f771

File tree

20 files changed

+843
-744
lines changed

20 files changed

+843
-744
lines changed

package-lock.json

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"release": "standard-version",
3030
"security": "npm audit --production",
3131
"test:only": "cross-env NODE_ENV=test jest",
32+
"test:only:experimental": "EXPERIMENTAL_USE_IMPORT_MODULE=true cross-env NODE_ENV=test jest",
3233
"test:watch": "npm run test:only -- --watch",
3334
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
3435
"test:manual": "npm run build && webpack serve ./test/manual/src/index.js --open --config ./test/manual/webpack.config.js",

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ class MiniCssExtractPlugin {
989989
let content = module.content.toString();
990990

991991
const readableIdentifier = module.readableIdentifier(requestShortener);
992+
const startsWithAtRuleImport = /^@import url/.test(content);
992993

993994
if (compilation.outputOptions.pathinfo) {
994995
// From https://github.com/webpack/webpack/blob/29eff8a74ecc2f87517b627dee451c2af9ed3f3f/lib/ModuleInfoHeaderPlugin.js#L191-L194
@@ -999,7 +1000,7 @@ class MiniCssExtractPlugin {
9991000
content = headerStr + content;
10001001
}
10011002

1002-
if (/^@import url/.test(content)) {
1003+
if (startsWithAtRuleImport) {
10031004
// HACK for IE
10041005
// http://stackoverflow.com/a/14676665/1458162
10051006
if (module.media) {

test/cases/at-import-in-entry/a.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
font-family: "Manrope";
3+
}

test/cases/at-import-in-entry/b.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import url(https://fonts.googleapis.com/css2?family=Manrope:wght@500;800&display=swap);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*!****************************************************************!*\
2+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css ***!
3+
\****************************************************************/
4+
@import url(https://fonts.googleapis.com/css2?family=Manrope:wght@500;800&display=swap);
5+
/*!****************************************************************!*\
6+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./a.css ***!
7+
\****************************************************************/
8+
body {
9+
font-family: "Manrope";
10+
}
11+
12+
/*!********************************************************************!*\
13+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css (1) ***!
14+
\********************************************************************/
15+
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Self from "../../../src";
2+
3+
module.exports = {
4+
mode: "development",
5+
entry: ["./a.css", "./b.css"],
6+
output: {
7+
pathinfo: true,
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/,
13+
use: [Self.loader, "css-loader"],
14+
},
15+
],
16+
},
17+
plugins: [
18+
new Self({
19+
filename: "[name].css",
20+
}),
21+
],
22+
};

test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
7373
/******/
7474
/******/ /* webpack/runtime/getFullHash */
7575
/******/ (() => {
76-
/******/ __webpack_require__.h = () => ("ab3ada7332542b91ceb4")
76+
/******/ __webpack_require__.h = () => ("d67c698e3fd6a71ab1e8")
7777
/******/ })();
7878
/******/
7979
/******/ /* webpack/runtime/global */
@@ -308,12 +308,14 @@ __webpack_require__.r(__webpack_exports__);
308308
/******/ // add "moreModules" to the modules object,
309309
/******/ // then flag all "chunkIds" as loaded and fire callback
310310
/******/ var moduleId, chunkId, i = 0;
311-
/******/ for(moduleId in moreModules) {
312-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
313-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
311+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
312+
/******/ for(moduleId in moreModules) {
313+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
314+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
315+
/******/ }
314316
/******/ }
317+
/******/ if(runtime) var result = runtime(__webpack_require__);
315318
/******/ }
316-
/******/ if(runtime) var result = runtime(__webpack_require__);
317319
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
318320
/******/ for(;i < chunkIds.length; i++) {
319321
/******/ chunkId = chunkIds[i];

test/cases/chunkFilename-fullhash/expected/webpack-5/main.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
7373
/******/
7474
/******/ /* webpack/runtime/getFullHash */
7575
/******/ (() => {
76-
/******/ __webpack_require__.h = () => ("05170166b8a070c9e23e")
76+
/******/ __webpack_require__.h = () => ("a4a1641571287dda5115")
7777
/******/ })();
7878
/******/
7979
/******/ /* webpack/runtime/global */
@@ -308,12 +308,14 @@ __webpack_require__.r(__webpack_exports__);
308308
/******/ // add "moreModules" to the modules object,
309309
/******/ // then flag all "chunkIds" as loaded and fire callback
310310
/******/ var moduleId, chunkId, i = 0;
311-
/******/ for(moduleId in moreModules) {
312-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
313-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
311+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
312+
/******/ for(moduleId in moreModules) {
313+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
314+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
315+
/******/ }
314316
/******/ }
317+
/******/ if(runtime) var result = runtime(__webpack_require__);
315318
/******/ }
316-
/******/ if(runtime) var result = runtime(__webpack_require__);
317319
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
318320
/******/ for(;i < chunkIds.length; i++) {
319321
/******/ chunkId = chunkIds[i];

test/cases/dependOn-multiple-files-per-entry/expected/common.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ __webpack_require__.r(__webpack_exports__);
126126
/******/ // add "moreModules" to the modules object,
127127
/******/ // then flag all "chunkIds" as loaded and fire callback
128128
/******/ var moduleId, chunkId, i = 0;
129-
/******/ for(moduleId in moreModules) {
130-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
131-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
129+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
130+
/******/ for(moduleId in moreModules) {
131+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
132+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
133+
/******/ }
132134
/******/ }
135+
/******/ if(runtime) var result = runtime(__webpack_require__);
133136
/******/ }
134-
/******/ if(runtime) var result = runtime(__webpack_require__);
135137
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
136138
/******/ for(;i < chunkIds.length; i++) {
137139
/******/ chunkId = chunkIds[i];

test/cases/dependOn/expected/common.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ __webpack_require__.r(__webpack_exports__);
117117
/******/ // add "moreModules" to the modules object,
118118
/******/ // then flag all "chunkIds" as loaded and fire callback
119119
/******/ var moduleId, chunkId, i = 0;
120-
/******/ for(moduleId in moreModules) {
121-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
122-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
120+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
121+
/******/ for(moduleId in moreModules) {
122+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
123+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
124+
/******/ }
123125
/******/ }
126+
/******/ if(runtime) var result = runtime(__webpack_require__);
124127
/******/ }
125-
/******/ if(runtime) var result = runtime(__webpack_require__);
126128
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
127129
/******/ for(;i < chunkIds.length; i++) {
128130
/******/ chunkId = chunkIds[i];

test/cases/hmr/expected/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ module.exports = function (urlString) {
946946
/******/ // object to store loaded and loading chunks
947947
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
948948
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
949-
/******/ var installedChunks = {
949+
/******/ var installedChunks = __webpack_require__.hmrS_jsonp = __webpack_require__.hmrS_jsonp || {
950950
/******/ 0: 0
951951
/******/ };
952952
/******/

test/cases/insert-function/expected/main.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,14 @@
298298
/******/ // add "moreModules" to the modules object,
299299
/******/ // then flag all "chunkIds" as loaded and fire callback
300300
/******/ var moduleId, chunkId, i = 0;
301-
/******/ for(moduleId in moreModules) {
302-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
303-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
301+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
302+
/******/ for(moduleId in moreModules) {
303+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
304+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
305+
/******/ }
304306
/******/ }
307+
/******/ if(runtime) var result = runtime(__webpack_require__);
305308
/******/ }
306-
/******/ if(runtime) var result = runtime(__webpack_require__);
307309
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
308310
/******/ for(;i < chunkIds.length; i++) {
309311
/******/ chunkId = chunkIds[i];

test/cases/insert-string/expected/main.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,14 @@
293293
/******/ // add "moreModules" to the modules object,
294294
/******/ // then flag all "chunkIds" as loaded and fire callback
295295
/******/ var moduleId, chunkId, i = 0;
296-
/******/ for(moduleId in moreModules) {
297-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
298-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
296+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
297+
/******/ for(moduleId in moreModules) {
298+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
299+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
300+
/******/ }
299301
/******/ }
302+
/******/ if(runtime) var result = runtime(__webpack_require__);
300303
/******/ }
301-
/******/ if(runtime) var result = runtime(__webpack_require__);
302304
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
303305
/******/ for(;i < chunkIds.length; i++) {
304306
/******/ chunkId = chunkIds[i];

test/cases/insert-undefined/expected/main.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,14 @@
292292
/******/ // add "moreModules" to the modules object,
293293
/******/ // then flag all "chunkIds" as loaded and fire callback
294294
/******/ var moduleId, chunkId, i = 0;
295-
/******/ for(moduleId in moreModules) {
296-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
297-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
295+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
296+
/******/ for(moduleId in moreModules) {
297+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
298+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
299+
/******/ }
298300
/******/ }
301+
/******/ if(runtime) var result = runtime(__webpack_require__);
299302
/******/ }
300-
/******/ if(runtime) var result = runtime(__webpack_require__);
301303
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
302304
/******/ for(;i < chunkIds.length; i++) {
303305
/******/ chunkId = chunkIds[i];

test/cases/runtime/expected/runtime~main.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,14 @@
295295
/******/ // add "moreModules" to the modules object,
296296
/******/ // then flag all "chunkIds" as loaded and fire callback
297297
/******/ var moduleId, chunkId, i = 0;
298-
/******/ for(moduleId in moreModules) {
299-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
300-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
298+
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
299+
/******/ for(moduleId in moreModules) {
300+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
301+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
302+
/******/ }
301303
/******/ }
304+
/******/ if(runtime) var result = runtime(__webpack_require__);
302305
/******/ }
303-
/******/ if(runtime) var result = runtime(__webpack_require__);
304306
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
305307
/******/ for(;i < chunkIds.length; i++) {
306308
/******/ chunkId = chunkIds[i];

0 commit comments

Comments
 (0)