Skip to content

Commit

Permalink
fix: order of @import with pathinfo (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Aug 31, 2021
1 parent 58637ca commit 831f771
Show file tree
Hide file tree
Showing 20 changed files with 843 additions and 744 deletions.
1,455 changes: 747 additions & 708 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -29,6 +29,7 @@
"release": "standard-version",
"security": "npm audit --production",
"test:only": "cross-env NODE_ENV=test jest",
"test:only:experimental": "EXPERIMENTAL_USE_IMPORT_MODULE=true cross-env NODE_ENV=test jest",
"test:watch": "npm run test:only -- --watch",
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
"test:manual": "npm run build && webpack serve ./test/manual/src/index.js --open --config ./test/manual/webpack.config.js",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -989,6 +989,7 @@ class MiniCssExtractPlugin {
let content = module.content.toString();

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

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

if (/^@import url/.test(content)) {
if (startsWithAtRuleImport) {
// HACK for IE
// http://stackoverflow.com/a/14676665/1458162
if (module.media) {
Expand Down
3 changes: 3 additions & 0 deletions test/cases/at-import-in-entry/a.css
@@ -0,0 +1,3 @@
body {
font-family: "Manrope";
}
1 change: 1 addition & 0 deletions test/cases/at-import-in-entry/b.css
@@ -0,0 +1 @@
@import url(https://fonts.googleapis.com/css2?family=Manrope:wght@500;800&display=swap);
16 changes: 16 additions & 0 deletions test/cases/at-import-in-entry/expected/main.css
@@ -0,0 +1,16 @@
/*!****************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css ***!
\****************************************************************/
@import url(https://fonts.googleapis.com/css2?family=Manrope:wght@500;800&display=swap);
/*!****************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./a.css ***!
\****************************************************************/
body {
font-family: "Manrope";
}

/*!********************************************************************!*\
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css (1) ***!
\********************************************************************/


22 changes: 22 additions & 0 deletions test/cases/at-import-in-entry/webpack.config.js
@@ -0,0 +1,22 @@
import Self from "../../../src";

module.exports = {
mode: "development",
entry: ["./a.css", "./b.css"],
output: {
pathinfo: true,
},
module: {
rules: [
{
test: /\.css$/,
use: [Self.loader, "css-loader"],
},
],
},
plugins: [
new Self({
filename: "[name].css",
}),
],
};
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("ab3ada7332542b91ceb4")
/******/ __webpack_require__.h = () => ("d67c698e3fd6a71ab1e8")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down Expand Up @@ -308,12 +308,14 @@ __webpack_require__.r(__webpack_exports__);
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
12 changes: 7 additions & 5 deletions test/cases/chunkFilename-fullhash/expected/webpack-5/main.js
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("05170166b8a070c9e23e")
/******/ __webpack_require__.h = () => ("a4a1641571287dda5115")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down Expand Up @@ -308,12 +308,14 @@ __webpack_require__.r(__webpack_exports__);
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
10 changes: 6 additions & 4 deletions test/cases/dependOn-multiple-files-per-entry/expected/common.js
Expand Up @@ -126,12 +126,14 @@ __webpack_require__.r(__webpack_exports__);
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
10 changes: 6 additions & 4 deletions test/cases/dependOn/expected/common.js
Expand Up @@ -117,12 +117,14 @@ __webpack_require__.r(__webpack_exports__);
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
2 changes: 1 addition & 1 deletion test/cases/hmr/expected/main.js
Expand Up @@ -946,7 +946,7 @@ module.exports = function (urlString) {
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
/******/ var installedChunks = {
/******/ var installedChunks = __webpack_require__.hmrS_jsonp = __webpack_require__.hmrS_jsonp || {
/******/ 0: 0
/******/ };
/******/
Expand Down
10 changes: 6 additions & 4 deletions test/cases/insert-function/expected/main.js
Expand Up @@ -298,12 +298,14 @@
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
10 changes: 6 additions & 4 deletions test/cases/insert-string/expected/main.js
Expand Up @@ -293,12 +293,14 @@
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
10 changes: 6 additions & 4 deletions test/cases/insert-undefined/expected/main.js
Expand Up @@ -292,12 +292,14 @@
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down
10 changes: 6 additions & 4 deletions test/cases/runtime/expected/runtime~main.js
Expand Up @@ -295,12 +295,14 @@
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
Expand Down

0 comments on commit 831f771

Please sign in to comment.