B
B
budda6742022-02-28 15:27:20
React
budda674, 2022-02-28 15:27:20

Outputting multiple files to a CRA build?

I use CRA(webpack4.4) & craco.js
It is necessary to make two files in the build, one must contain a hash in the name (standard output) and in the same folder with the bundle + the same js file only without the hash in the name

!! It is important that all this happens on one build command !!

Craco config example:

const hash = {
    webpack: {
        configure: {
            entry: 'src/index',
            output: {
                filename: "static/js/[name].[contenthash:8].js"
            },
            optimization: {
                runtimeChunk: false,
                splitChunks: {
                    chunks(chunk) {
                        return false;
                    },
                },
            },
        },
    },
    plugins: [
        {
            plugin: {
                overrideWebpackConfig: ({ webpackConfig }) => {
                    webpackConfig.plugins[5].options.filename = "static/css/[name].[contenthash:8].css";
                    return webpackConfig;
                },
            },
            options: {},
        },
    ],
};

const withoutHash = {
    webpack: {
        configure: {
            entry: 'src/index',
            output: {
                filename: "static/js/[name].js"
            },
            optimization: {
                runtimeChunk: false,
                splitChunks: {
                    chunks(chunk) {
                        return false;
                    },
                },
            },
        },
    },
    plugins: [
        {
            plugin: {
                overrideWebpackConfig: ({ webpackConfig }) => {
                    webpackConfig.plugins[5].options.filename = "static/css/[name].css";
                    return webpackConfig;
                },
            },
            options: {},
        },
    ],
};


module.exports = [hash, withoutHash]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question