Questions tagged [terser]

Terser is a JavaScript parser and mangler/compressor toolkit for ES6+ (ECMAScript 6+ / JavaScript 6+)

Terser is a JavaScript parser and mangler/compressor toolkit for ES6+ (ECMAScript 6+ / JavaScript 6+). It is a fork of uglify-es which doesn't support ES6+ any longer.

128 questions
23
votes
1 answer

TypeError: Cannot read property 'javascript' of undefined + terser webpack plugin + react js

I recently added terser-webpack-plugin to minify my create react app code. But while build the project I got an error like TypeError: Cannot read property 'javascript' of undefined. Below are some logs from my console. Please let me know of any…
SakthiSureshAnand
  • 1,324
  • 16
  • 32
15
votes
2 answers

UglifyJS and webpack v5

We've been using UglifyJS and webpack v4 for our react code, but then just updated to webpack v5. It appears that UglifyJS does not work with webpack v5. Is there an alternative? We need something that works with babel-loader. Thanks
vgoklani
  • 10,685
  • 16
  • 63
  • 101
13
votes
3 answers

WebPack+TerserPlugin: mangle ignores properties and class names – poor quality of the mangled code

The resulting code is minified but almost not mangled. This is how it looks like in the Google Chrome (beautified): All properties names, lots of variables have their original names. Even with Terser's mangle options specified explicitly:…
Oleg Zarevennyi
  • 2,753
  • 1
  • 21
  • 21
10
votes
1 answer

How to configure terserplugin to not mangle classnames

Classnames are mangled during minification, but that should not be done I tried setting the reserved property when mangling as described here https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions. Unfortunately that doesn't work for…
Johan Beumer
  • 131
  • 1
  • 7
8
votes
1 answer

ERROR in main.js from Terser when compiling with webpack

So I'm trying to run webpack to compile my code, but when I run npx webpack --config webpack.config.js I get the following error: ERROR in main.js from Terser Invalid assignment [main.js:78674,15] There's not much to go off of, I'm not even sure…
ajnauleau
  • 449
  • 4
  • 9
7
votes
0 answers

How to make webpack+terser inline functions across chunks?

I've got a function defined in an ES module that I'd like to make sure inlines. This works fine when it's only used in one chunk, but if I call the function from two separate chunks, webpack generates module lookup patterns that prevent…
Steve
  • 1,541
  • 11
  • 17
7
votes
3 answers

Idiomatic Conditional TypeScript compilation in Angular

I'm using Angular 9 and I have some code like this: (features.ts, autogenerated:) // AUTO-GENERTATED FILE. DO NOT EDIT! export const Features = { // Whether to reveal our Secret New Feature to the world ENABLE_SECRET_FEATURE: 1 }; (mycode.ts,…
Gavin
  • 6,495
  • 3
  • 21
  • 22
7
votes
1 answer

Vue CLI 3 vue.config.js vs webpack.config.js for plugins

I'm using Vue CLI 3, and I need to add the Terser Webpack Plugin for removing console.log and comments from the code. This isn't working with my current setup - logs and comments are still in the build. My production workflow: Run npm run build Run…
Tom
  • 5,588
  • 20
  • 77
  • 129
7
votes
3 answers

Terser does not give minified file

I am trying to minify an angularjs application using grunt and terser. I first used uglifiy-es but then read that it has some issues. So I tried terser. But the output does not give me minified files. The gruntfile.js module.exports =…
Dwigh
  • 441
  • 5
  • 19
6
votes
0 answers

Webpack TerserPlugin Excludes

One of my Node Modules in my React project uses vm.runincontext and this code isn't being able to run while minified. My current solution has been to turn minification off and it works it just makes loading take a long time :(. I was thinking to…
Amit
  • 157
  • 8
5
votes
0 answers

How can I get bundlephobia to show different sizes in export analysis?

So I'm using bundlephobia to audit the bundle size of my packages. Bundlephobia has a section called "Export Analysis" that gives you the bundle size of the individual exports. So each of these functions in this bundle are pure functions so, unless…
Rico Kahler
  • 17,616
  • 11
  • 59
  • 85
5
votes
1 answer

Vue CLI 3 remove console.log and code comments with Terser

I'm using VUE CLI 3 and I need to remove the console.log and code comments from the production built. This is my Terser setup: webpack.config.js in src folder module.exports = { mode: 'production', optimization: { minimize: true, …
Tom
  • 5,588
  • 20
  • 77
  • 129
4
votes
1 answer

Typescript const enum alternative

More and more modern Typescript transpilers have moved toward a strategy of per-module transpilation, which significantly increases build speed, but eliminates the possibility for cross-module const enum usage, since transpilation of them requires…
casieber
  • 7,264
  • 2
  • 20
  • 34
4
votes
0 answers

Minifying a CSS file using terser

I have had some success minifying a .js file using terser. However, I have so far not been able to minify a standalone CSS file, and this is the reason for this qestion. I have installed html-minifier-terser, which minifies an HTML file, including…
sg1234
  • 600
  • 4
  • 19
4
votes
1 answer

Can Webpack tree-shake to remove imports already removed by tree-shaking

Can Webpack be configured so that its tree-shaking is smart enough to remove imports depended on by only other tree-shaken exports? Example: entry.js import { apple } from './appleBanana'; console.log(apple()); appleBanana.js import { mango, orange…
1
2 3
8 9