M
M
m5xim2021-06-07 14:06:49
JavaScript
m5xim, 2021-06-07 14:06:49

How to disable the generation of extras in webpack terser code?

There is a project in which web components will be used. To minify the current js code, the Webpack Terser plugin is used (more precisely, laravel mix, but it uses Terser), however, this approach generates a lot of redundant code (example below). In the case of web components, each file will be minified separately, and this amount of redundant code is not acceptable. Is there a way to disable this i.e. leave only the removal of spaces, the replacement of names with letters, but without all these shells? Support for older browsers is not interested.
Tried specifying a higher version in ecma but that didn't help

Redundant code example

function _classCallCheck(e, t) {
            if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
        }

        function _defineProperties(e, t) {
            for (var r = 0; r < t.length; r++) {
                var n = t[r];
                n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
            }
        }

        function _possibleConstructorReturn(e, t) {
            return !t || "object" !== _typeof(t) && "function" != typeof t ? function _assertThisInitialized(e) {
                if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
                return e
            }(e) : t
        }

         function _wrapNativeSuper(e) {
            var t = "function" == typeof Map ? new Map : void 0;
            return (_wrapNativeSuper = function _wrapNativeSuper(e) {
                if (null === e || !function _isNativeFunction(e) { ...



UPD: These were Babel polyfills and I found a way to avoid creating them :
webpack.mix.js:
// makes babel is dependent on package.json browserslist, so will skip additional polyfills
        laravelMix.babelConfig({
            "presets": [
                [
                    "@babel/preset-env",
                    {}
                ]
            ]
        });

package.json
"browserslist": [
    "last 3 Firefox versions",
    "last 3 Chrome versions",
    "last 3 Safari versions",
    "last 3 FirefoxAndroid versions",
    "last 3 ChromeAndroid versions",
    "last 3 iOS versions"
  ]

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