Skip to content

Commit 64cdb8c

Browse files
karlvrmastilver
authored andcommitted
Fix mini-css-extract-plugin 0.4.3 issue
mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`. See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177 fixes #167
1 parent 9303a82 commit 64cdb8c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/plugin.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ ManifestPlugin.prototype.apply = function(compiler) {
4949
}
5050
};
5151

52+
// TODO: check with @evilebottnawi if this is still needed for webpack@5
53+
var normalModuleLoader = function (loaderContext, module) {
54+
const { emitFile } = loaderContext;
55+
56+
loaderContext.emitFile = (file, content, sourceMap) => {
57+
if (module.userRequest && !moduleAssets[file]) {
58+
moduleAssets[file] = path.join(
59+
path.dirname(file),
60+
path.basename(module.userRequest)
61+
);
62+
}
63+
64+
return emitFile.call(module, file, content, sourceMap);
65+
};
66+
};
67+
5268
var emit = function(compilation, compileCallback) {
5369
const emitCount = emitCountMap.get(outputFile) - 1
5470
emitCountMap.set(outputFile, emitCount);
@@ -214,7 +230,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
214230
compiler.hooks.webpackManifestPluginAfterEmit = new SyncWaterfallHook(['manifest']);
215231

216232
compiler.hooks.compilation.tap(pluginOptions, function (compilation) {
217-
compilation.hooks.moduleAsset.tap(pluginOptions, moduleAsset);
233+
compilation.hooks.normalModuleLoader.tap(pluginOptions, normalModuleLoader);
218234
});
219235
compiler.hooks.emit.tap(pluginOptions, emit);
220236

0 commit comments

Comments
 (0)