How can I avoid losing my class name when I bundle source with webpack in production mode?

invalid :

When I bundle code below in development mode and run abc(),

class Foo { ... }

export function abc () { return new Foo(); }

I got Foo { ... }.

But bundle with production mode, I got something like k { ... } and I lost information about class name.

How can I avoid this?

In other words, I want to minify code except class name because I want to use source as a library with npm install my-github-repository and require("abc").

liang ma :

webpack configure sourcemap and then use the uglifyjs-webpack-plugin package to set the output souremap to keep the class name and function name

new UglifyJsPlugin({
    sourceMap: true,
    parallel: 4,
    uglifyOptions: {
        keep_classnames: true,
        keep_fnames: true
    }
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=198016&siteId=1