Skip to content

Improve CopyWebpackPlugin with WebpackManifestPlugin workflow #1089

Description

@shadowc

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions