Open
Description
Let's improve on this PR to be able to use CopyWebpackPlugin AND add hashes to the destination files when needed: #409
For reference on how we could accomplish this, the ManifestPlugin can be used to produce hashed files for the CopyWebpackPlugin when needed (code from my personal website):
return new ManifestPlugin({
filter(fileDescriptor) {
// Filter out some weirdness coming from source scss files
return !fileDescriptor.name.match(/.scss$/);
},
map(fileDescriptor) {
// Correct entries regarding the copy-webpack-plugin
// adding hashes to both handle and file name
const copyReplacePattern = new RegExp(
`(${config.serverPath}/images/backgrounds)/(.+)-([0-9a-f]{8}).(jpg)`,
);
const copyMatches = fileDescriptor.name.match(copyReplacePattern);
if (copyMatches && copyMatches.length === 5) {
fileDescriptor.name = `${config.serverPath}/images/backgrounds/${copyMatches[2]}.${copyMatches[4]}`;
}
return fileDescriptor;
},
writeToFileEmit: true,
basePath: `${config.serverPath}/`,
publicPath: config.isHmr
? `//${config.serverHost}:${config.serverPort}/${config.serverPath}/`
: `/${config.serverPath}/`,
});
This function knows in advance that the only copied files are some images I had in a specific directory, but we can adapt this logic to fix hashes going into the manifest in a more general way.
With this, we could probably stop using the forked WebpackManifestPlugin, as @weaverryan said:
but I think maybe we don’t need that anymore, as the PR I linked to IS merged now
So we could probably require the plugin again at version 3.1.1 or higher
... and work our way from there.
So, to summarize, from @weaverryan :
So, things we could do:
- Re-add WebpackManifestPlugin properly (instead of using a copy)
- Investigate getting CopyWebpackPlugin working with WebpackManifestPlugin (found this [Feature] Support manifest file webpack-contrib/copy-webpack-plugin#104 (comment) )
- If we do (A) and (B), we could deprecate our custom copy() functionality, which is pretty complex
Metadata
Metadata
Assignees
Labels
No labels