MultiModule.identifier can have absolute paths
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;
}
another case:
- use
ContextReplacementPluginto force ignoring some modules. ie,new webpack.ContextReplacementPlugin(/react-intl\/locale-data/, {yourRegexp}), - 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;
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
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.