A general-purpose JavaScript parser/compressor/beautifier toolkit developed on Node.js
Questions tagged [uglifyjs2]
112 questions
94
votes
8 answers
UglifyJS throws unexpected token: keyword (const) with node_modules
A small project I started make use a node module (installed via npm) that declares const variables. Running and testing this project is well, but browserify fails when UglifyJS is executed.
Unexpected token: keyword (const)
Here is a generic Gulp…

Yanick Rochon
- 51,409
- 25
- 133
- 214
51
votes
10 answers
How to minify multiple Javascript files in a folder with UglifyJS?
Hello I'm using uglifyJs to minify my javascript files, it's working well with one file at a time, what I'm loking for is to minify all the javascript files present in a folder called JS into a folder called JSM, to be clear I have 2 files inside my…

OussamaLord
- 1,073
- 5
- 28
- 39
42
votes
5 answers
Can uglify-js remove the console.log statements?
I'm using uglify-js to minify the source code. I want to remove the console.log statements of the original source code. Is it possible? Or is there any other compressor tool supports this?
I use the code as below in Node.js.
var uglify =…

Jeffrey
- 4,436
- 9
- 38
- 54
27
votes
2 answers
How to exclude certain requireJS files from uglifying/optimizing
I have a working requirejs project that is using grunt for building and deployment. If using no optimization at all, the build is working without problems and I get one big js file to deploy it on production.
The problem I have is, that I have some…

Marco Rinck
- 738
- 2
- 6
- 17
20
votes
6 answers
Failed to minify the code from this file
I am authoring a JavaScript library that I want to put on npm. I am currently using that library in another project and I have added it as a dependency using its GitHub repository:
"dependencies": {
// ... others
"react-web-component":…

Lukas
- 9,752
- 15
- 76
- 120
16
votes
4 answers
Using UglifyJs on the whole Node project?
I need to obfuscate my source code as best as possible so I decided to use uglifyjs2.. Now I have the project structure that has nested directories, how can I run it through uglifyjs2 to do the whole project instead of giving it all the input…

Tolga E
- 12,188
- 15
- 49
- 61
12
votes
2 answers
How to parse and iterate prototype methods with Uglify.js?
I 'd like to parse some JavasScript code to list all methods for a given "class" using uglify js 2. In my case the TreeWalker returns a node with name : null and there is no information that allow conclusions to parent.
Does anyone know a different…

Stephan Ahlf
- 3,310
- 5
- 39
- 68
12
votes
2 answers
Tell UglifyJS to skip a particular area of code
Is there a way to tell UglifyJS to skip a particular section of code, perhaps using comments like this:
// uglifyjs:skipStart
filter = function(item){ /* some crazy filter logic that will repeat 500,000 times */ }
// uglifyjs:skipEnd
My use case…

SimplGy
- 20,079
- 15
- 107
- 144
11
votes
1 answer
Batch File Exits After Running One Node Application Script
I need to run several UglifyJS2 scripts with Node. I've added the command I want to run to a bat file and it runs OK.
When I add a second command, like "cd ..", the command isn't executed! Very confusing.
cd go somewhere
uglifyjs ..\somescript -o…

Greg
- 3,086
- 3
- 26
- 39
10
votes
5 answers
Mangle nested classes and variables with UglifyJS
I use UglifyJS to minify a concatenated set of files, which works fine but not good enough. The built lib uses namespaces, so classes, functions and constants are stored in a root namespace variable:
(function() {
var root = { api:{}, core:{},…

whadar
- 4,181
- 4
- 19
- 21
9
votes
2 answers
Lodash not TreeShaking with Webpack with Webpack 4?
I want to tree shake lodash as well as my unused multiply function from the generated bundle from webpack
I have 2 main files app.js & math.js
It contains the following code -
app.js
import map from "lodash/map";
import { sum } from…

deadcoder0904
- 7,232
- 12
- 66
- 163
9
votes
2 answers
UglifyJS webpack plugin throws: Unexpected token: name (features)
I used to have problems with UglifyJS for Webpack and ES6 modules:
ERROR in static/js/vendor.6ccd9e38979a78765c7a.js from UglifyJs
Unexpected token: name (features)
…

alex
- 7,111
- 15
- 50
- 77
9
votes
3 answers
Uglify with SourceMaps while using grunt usemin and rev
I want to log javascript errors to server but the stacktrace is not useful with minified JS code. So I was thinking of using either Getsentry or Rollbar which shows proper stack trace with the help of sourcemaps. But I'm struggling to create…

IsmailS
- 10,797
- 21
- 82
- 134
8
votes
1 answer
UglifyJS property mangling
According to the docs, UglifyJS can mangle all property names except those on a provided reserved list. Is it possible to do it the other way, so only properties on provided list will be mangled?
If so, what options do I need to pass to…

Sebastian Nowak
- 5,607
- 8
- 67
- 107
7
votes
1 answer
Keep license comments when using UglifyJS2 with gulp plugin
In this project i am using gulp-uglify version 3.0.1 and i want to preserve comments containing license texts in the output.
On the projects page it is stated that
Most of the minify options from the UglifyJS API are supported.
and this answer…

x29a
- 1,761
- 1
- 24
- 43