Skip to content

Commit

Permalink
Fix mini-css-extract-plugin 0.4.3 issue
Browse files Browse the repository at this point in the history
Second attempt. Based on webdeveric/webpack-assets-manifest#40

Resolves shellscape#167

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
  • Loading branch information
karlvr committed Jan 29, 2020
1 parent a664d77 commit 0c1dc4d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/plugin.js
Expand Up @@ -60,14 +60,28 @@ ManifestPlugin.prototype.apply = function(compiler) {
var outputName = path.relative(outputFolder, outputFile);

var moduleAsset = function (module, file) {
if (module.userRequest && !moduleAssets[file]) {
if (module.userRequest) {
moduleAssets[file] = path.join(
path.dirname(file),
path.basename(module.userRequest)
);
}
};

var normalModuleLoader = function (loaderContext, module) {
const { emitFile } = loaderContext;

loaderContext.emitFile = (file, content, sourceMap) => {
if (module.userRequest && !moduleAssets[file]) {
moduleAssets[file] = path.join(
path.dirname(file),
path.basename(module.userRequest)
);
}

return emitFile.call(module, file, content, sourceMap);
};
};

var emit = function(compilation, compileCallback) {
const emitCount = emitCountMap.get(outputFile) - 1
Expand Down Expand Up @@ -251,7 +265,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
}

compiler.hooks.compilation.tap(pluginOptions, function (compilation) {
compilation.hooks.moduleAsset.tap(pluginOptions, moduleAsset);
compilation.hooks.normalModuleLoader.tap(pluginOptions, normalModuleLoader);
});
compiler.hooks.emit.tap(pluginOptions, emit);

Expand Down

0 comments on commit 0c1dc4d

Please sign in to comment.