Webpack renames functions

610 views Asked by At

Hello i have some problems with webpack. I have this config for webpack

module.exports = {
    name: "front",
    mode: "production",
    context: path.resolve(__dirname, 'src'),
    entry: [
        './jquery/photoswipe.addon_offer_and_order.min.js',
        './jquery/photoswipe.min.js',
        './jquery/photoswipe-ui-default.min.js',
        './deprecated.js',
        './index.js',
    ],
    output: {
        filename: "index.min.js",
        path: path.resolve(__dirname, 'dist')
    },
    optimization: {
        moduleIds: 'named'
    }
}

All good but i have a deprecated.js and have all deprecated functions in it...

Example:

function updateSearchCharacteristic(url, category_id) {
    console.warn("This method is deprecated please use shopSearch.updateCharacteristic()");
    return shopSearch.updateCharacteristic(url, category_id);
}

function moveBlockAnfrageGuest() {
    console.warn("This method is deprecated please use shopUser.moveOrderAndOfferLinkForGuest()");
    return shopUser.moveOrderAndOfferLinkForGuest();
}

Webpack rename all these functions, if someone used the old functions, he does not see errors and the return does not work .. How not to rename functions in this file, but compress

1

There are 1 answers

0
Richard On BEST ANSWER

I resolved this problem :

npm install -D script-loader terser-webpack-plugin

Added a module into config and 'require' a plugin

const TerserPlugin  = require('terser-webpack-plugin')

 module: {
        rules: [
            {
                test: /deprecated.js/,
                use : [
                    {
                        loader: 'script-loader',
                        options:{
                            plugins: [
                                new TerserPlugin({
                                    terserOptions: {
                                        keep_fnames: true,
                                    }
                                })
                            ]
                        }
                    }
                ]
            }
        ]
    }