2

I've tried many things to disable webpack's minify because I need my function names to remain intact. All of this for CEF.

Here's my code: (I've also tried the commented UglifyJSPlugin config.)

const config = {
...
    "optimization": {
        "minimize": false
        /*[
            new UglifyJSPlugin({
                "test": /\.(js|jsx)$/,
                "uglifyOptions": {
                    "ecma": 6,
                    "warnings": true,
                    "mangle": false,
                    "keep_fnames": true,
                    "output": {
                        "beautify": false,
                        "comments": false
                    }
                }
            })
        ]*/
    },
...
                "test": /\.(js|jsx)$/,
                "exclude": /node_modules/,
                "use": {
                    "loader": "babel-loader",
                    "options": {
                        "presets": [
                            "@babel/env",
                            "@babel/react"
                        ]
                    }

I know I don't need babel-loader, but I have no choice since script-loader doesn't have nodejs compatibility anymore.

Help much appreciated, thank you!

Gabriel Munt
  • 29
  • 1
  • 3
  • 2
    Not sure why `"minimize": false` does not do the job, since an [accepted answer](https://stackoverflow.com/a/51264532/6361314) suggests that it should. Nevertheless you could try using [`"mode": "development"`](https://webpack.js.org/guides/development/). – JJWesterkamp Jan 11 '19 at 20:33
  • Thank you @JeffreyWesterkamp . It's always been in development, so I don't exactly know why it just always minifies. I have both --mode=development and "mode": "development" and it still does. – Gabriel Munt Jan 11 '19 at 20:38
  • Are you sure that webpack is not using a different config perhaps? If not this is pretty strange. – JJWesterkamp Jan 11 '19 at 20:39
  • Yes, I am sure. It follows if I change the entry file or if I change other options. – Gabriel Munt Jan 11 '19 at 20:44
  • 1
    Deleted the bundled file and it worked. – Gabriel Munt Jan 11 '19 at 20:57
  • What bundled file did you delete? – Longblog Apr 07 '23 at 01:03

1 Answers1

0

You can use the terser-webpack-plugin and change configurations to preserve the original variable/function names.

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

module.exports = {
  optimization: {
    minimizer: [
      new TerserPlugin({
        parallel: true,
        terserOptions: {
          // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
        },
      }),
    ],
  },
};
Anonymous
  • 57
  • 1
  • 6