name-all-modules-plugin icon indicating copy to clipboard operation
name-all-modules-plugin copied to clipboard

MultiModule.identifier can have absolute paths

Open anilanar opened this issue 8 years ago • 3 comments

The edge case this plugin targets is MultiModule. However a MultiModule can have dependencies that are absolute paths to some modules. Thus identifier() would have those absolute paths which breaks hash stability when path of the project is different across compilations.

Although there's a way to prevent it in user-land using aliases, perhaps this plugin can try to handle it. Something along these lines

var createHash = require("crypto").createHash;

function myIdentifier(module) {
  // SingleEntryDependency.module is always a NormalModule with id?
  var id = module.dependencies.map(singleEntryDep => singleEntryDep.module && singleEntryDep.module.id).join('.');
  if (id.length > 16) {
    var hash = createHash('md5');
    hash.update(id);
    return hash.digest('base64').substr(0, 16);
  }
  return id;
}

anilanar avatar May 23 '17 21:05 anilanar

another case:

  1. use ContextReplacementPlugin to force ignoring some modules. ie,new webpack.ContextReplacementPlugin(/react-intl\/locale-data/, {yourRegexp}),
  2. check result bundle. there will be something like "ignored {absolute path}/node_modules/react-intl/lib ../locale-data/index.js":

not sure if it covers case that's described above, but I fixed my problem with

module.id = module.readableIdentifierStr;

mshustov avatar May 30 '17 09:05 mshustov

sorry for the late reply and thanks for the catch. Happy to accept a PR on this. Currently not having the time but will try this WE

timse avatar Jun 07 '17 11:06 timse

I noticed in webpack-4 when using optimization.namedModules it executed after the NameAllModulesPlugin in the plugins array. When this happened, the indentifier() resulted in an absolute path.

Setting optimization.namedModules to false and adding the webpack.NamedModulesPlugin to the plugins array before NameAllModulesPlugin fixed this for me.

glen-cheney avatar Mar 22 '18 21:03 glen-cheney