Skip to content

Commit f0358d0

Browse files
committed
fix wrong modules after disable extraction
1 parent 2f29038 commit f0358d0

File tree

3 files changed

+226
-1
lines changed

3 files changed

+226
-1
lines changed

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class MiniCssExtractPlugin {
144144

145145
apply(compiler) {
146146
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
147-
const moduleToBeRebuild = new Set();
147+
let moduleToBeRebuild = new Set();
148148
// eslint-disable-next-line no-param-reassign
149149
compilation[MODULE_TYPE] = {
150150
moduleToBeRebuild,
@@ -456,6 +456,15 @@ class MiniCssExtractPlugin {
456456
Promise.all(promises).then(() => callback());
457457
}
458458
);
459+
460+
// Trigger seal again if there are modules to be rebuilt
461+
compilation.hooks.needAdditionalSeal.tap(pluginName, () => {
462+
if (moduleToBeRebuild.size > 0) {
463+
moduleToBeRebuild = new Set();
464+
return true;
465+
}
466+
return false;
467+
});
459468
});
460469
}
461470

test/cases/disable-extract-func/expected/1.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,121 @@ module.exports = exports;
7979

8080
// extracted by mini-css-extract-plugin
8181

82+
/***/ }),
83+
/* 11 */,
84+
/* 12 */,
85+
/* 13 */,
86+
/* 14 */
87+
/***/ (function(module, exports, __webpack_require__) {
88+
89+
"use strict";
90+
91+
92+
/*
93+
MIT License http://www.opensource.org/licenses/mit-license.php
94+
Author Tobias Koppers @sokra
95+
*/
96+
// css base code, injected by the css-loader
97+
// eslint-disable-next-line func-names
98+
module.exports = function (useSourceMap) {
99+
var list = []; // return the list of modules as css string
100+
101+
list.toString = function toString() {
102+
return this.map(function (item) {
103+
var content = cssWithMappingToString(item, useSourceMap);
104+
105+
if (item[2]) {
106+
return "@media ".concat(item[2], " {").concat(content, "}");
107+
}
108+
109+
return content;
110+
}).join('');
111+
}; // import a list of modules into the list
112+
// eslint-disable-next-line func-names
113+
114+
115+
list.i = function (modules, mediaQuery, dedupe) {
116+
if (typeof modules === 'string') {
117+
// eslint-disable-next-line no-param-reassign
118+
modules = [[null, modules, '']];
119+
}
120+
121+
var alreadyImportedModules = {};
122+
123+
if (dedupe) {
124+
for (var i = 0; i < this.length; i++) {
125+
// eslint-disable-next-line prefer-destructuring
126+
var id = this[i][0];
127+
128+
if (id != null) {
129+
alreadyImportedModules[id] = true;
130+
}
131+
}
132+
}
133+
134+
for (var _i = 0; _i < modules.length; _i++) {
135+
var item = [].concat(modules[_i]);
136+
137+
if (dedupe && alreadyImportedModules[item[0]]) {
138+
// eslint-disable-next-line no-continue
139+
continue;
140+
}
141+
142+
if (mediaQuery) {
143+
if (!item[2]) {
144+
item[2] = mediaQuery;
145+
} else {
146+
item[2] = "".concat(mediaQuery, " and ").concat(item[2]);
147+
}
148+
}
149+
150+
list.push(item);
151+
}
152+
};
153+
154+
return list;
155+
};
156+
157+
function cssWithMappingToString(item, useSourceMap) {
158+
var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring
159+
160+
var cssMapping = item[3];
161+
162+
if (!cssMapping) {
163+
return content;
164+
}
165+
166+
if (useSourceMap && typeof btoa === 'function') {
167+
var sourceMapping = toComment(cssMapping);
168+
var sourceURLs = cssMapping.sources.map(function (source) {
169+
return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */");
170+
});
171+
return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
172+
}
173+
174+
return [content].join('\n');
175+
} // Adapted from convert-source-map (MIT)
176+
177+
178+
function toComment(sourceMap) {
179+
// eslint-disable-next-line no-undef
180+
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
181+
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
182+
return "/*# ".concat(data, " */");
183+
}
184+
185+
/***/ }),
186+
/* 15 */
187+
/***/ (function(module, exports, __webpack_require__) {
188+
189+
// Imports
190+
var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(14);
191+
exports = ___CSS_LOADER_API_IMPORT___(false);
192+
// Module
193+
exports.push([module.i, ".async-import {\n background: black;\n}\n", ""]);
194+
// Exports
195+
module.exports = exports;
196+
197+
82198
/***/ })
83199
]]);

test/cases/disable-extract-func/expected/3.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,105 @@ exports.push([module.i, ".is-async-1 {\n background: magenta;\n}\n", ""]);
5959
module.exports = exports;
6060

6161

62+
/***/ }),
63+
/* 14 */
64+
/***/ (function(module, exports, __webpack_require__) {
65+
66+
"use strict";
67+
68+
69+
/*
70+
MIT License http://www.opensource.org/licenses/mit-license.php
71+
Author Tobias Koppers @sokra
72+
*/
73+
// css base code, injected by the css-loader
74+
// eslint-disable-next-line func-names
75+
module.exports = function (useSourceMap) {
76+
var list = []; // return the list of modules as css string
77+
78+
list.toString = function toString() {
79+
return this.map(function (item) {
80+
var content = cssWithMappingToString(item, useSourceMap);
81+
82+
if (item[2]) {
83+
return "@media ".concat(item[2], " {").concat(content, "}");
84+
}
85+
86+
return content;
87+
}).join('');
88+
}; // import a list of modules into the list
89+
// eslint-disable-next-line func-names
90+
91+
92+
list.i = function (modules, mediaQuery, dedupe) {
93+
if (typeof modules === 'string') {
94+
// eslint-disable-next-line no-param-reassign
95+
modules = [[null, modules, '']];
96+
}
97+
98+
var alreadyImportedModules = {};
99+
100+
if (dedupe) {
101+
for (var i = 0; i < this.length; i++) {
102+
// eslint-disable-next-line prefer-destructuring
103+
var id = this[i][0];
104+
105+
if (id != null) {
106+
alreadyImportedModules[id] = true;
107+
}
108+
}
109+
}
110+
111+
for (var _i = 0; _i < modules.length; _i++) {
112+
var item = [].concat(modules[_i]);
113+
114+
if (dedupe && alreadyImportedModules[item[0]]) {
115+
// eslint-disable-next-line no-continue
116+
continue;
117+
}
118+
119+
if (mediaQuery) {
120+
if (!item[2]) {
121+
item[2] = mediaQuery;
122+
} else {
123+
item[2] = "".concat(mediaQuery, " and ").concat(item[2]);
124+
}
125+
}
126+
127+
list.push(item);
128+
}
129+
};
130+
131+
return list;
132+
};
133+
134+
function cssWithMappingToString(item, useSourceMap) {
135+
var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring
136+
137+
var cssMapping = item[3];
138+
139+
if (!cssMapping) {
140+
return content;
141+
}
142+
143+
if (useSourceMap && typeof btoa === 'function') {
144+
var sourceMapping = toComment(cssMapping);
145+
var sourceURLs = cssMapping.sources.map(function (source) {
146+
return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */");
147+
});
148+
return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
149+
}
150+
151+
return [content].join('\n');
152+
} // Adapted from convert-source-map (MIT)
153+
154+
155+
function toComment(sourceMap) {
156+
// eslint-disable-next-line no-undef
157+
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
158+
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
159+
return "/*# ".concat(data, " */");
160+
}
161+
62162
/***/ })
63163
]]);

0 commit comments

Comments
 (0)