Skip to content

Improve CopyWebpackPlugin with WebpackManifestPlugin workflow #1089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks
shadowc opened this issue Feb 9, 2022 · 1 comment
Open
3 tasks

Improve CopyWebpackPlugin with WebpackManifestPlugin workflow #1089

shadowc opened this issue Feb 9, 2022 · 1 comment

Comments

@shadowc
Copy link

shadowc commented Feb 9, 2022

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:

@weaverryan
Copy link
Member

Sounds great! Let's do it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants