Questions tagged [uglifyjs2]

A general-purpose JavaScript parser/compressor/beautifier toolkit developed on Node.js

112 questions
7
votes
1 answer

UglifyJS options to only remove dead code

Is there a way to call the UglifyJS2 API in a node script (ie by calling require('uglify-js').minify) on a string of code such that it removes dead/unreachable code but does not apply any compression For example: var foo = 'bar'; if (false) { …
JoeR
  • 1,861
  • 3
  • 24
  • 38
7
votes
1 answer

Source maps with grunt

Do you know of a workflow that includes source maps for an app compiled with grunt? I am well aware of plugins like uglifyjs that allow you to simply generate a source map. But I'm looking for incorporating this into a more complex workflow, rather…
jamesplease
  • 11,679
  • 6
  • 42
  • 69
6
votes
1 answer

Extract individual javascript file code from minified file

I have a list of .js files and I have a single minified version of these files with the source map. The minified file has been created using UglifyJS Is it possible to extract code of the individual js files from the minified file? maybe by reading…
Imraan Khan
  • 315
  • 1
  • 2
  • 9
6
votes
1 answer

Pound Sign (#) As Comment Start In JavaScript?

Does the pound sign (#) start a comment in JavaScript? I have a website I am using with NPM and when I tried to minify the JavaScript with Grunt, Uglify threw the error: Warning: Uglification failed. Unexpected character '#'. Line 1 in…
trysis
  • 7,124
  • 12
  • 47
  • 74
6
votes
2 answers

How to uglify JavaScript using UglifyJS 2?

I tried to uglify a simple javascript file using UglifyJS2. Here are the contents of the file : //this is simply a sample var var sampleVar = "xyz"; //lots of comments //this is just another comment //such things should not be present in…
Kazekage Gaara
  • 14,516
  • 13
  • 53
  • 104
5
votes
1 answer

Limit line length with requirejs + uglify

We're using requirejs.optimize(config) with uglify2 in our build scripts to minify our production JavaScript code. We want to limit the minified line length to about 80 chars, so that it will be easier to debug JavaScript errors even from the…
Sampo
  • 2,619
  • 3
  • 25
  • 38
5
votes
1 answer

How to run UglifyJS2 without Node.JS

Anyway to run UglifyJS2 without node.js? Say I would like to run it in a JVM process using JavaScript script engine. How to do that?
Gelin Luo
  • 13,399
  • 23
  • 77
  • 119
4
votes
0 answers

Uglify: generate source map but don't append sourceMappingURL comment

I am using UglifyJS2 to minify javascript source code. I would like to generate source maps and point to those source maps using the X-SourceMap HTTP header, instead of the //# sourceMappingURL comment. So, is there a facility to generate a…
bcr
  • 1,298
  • 11
  • 26
4
votes
1 answer

Running UglifyJS under node.js generates cannot find module error

Running node.js v0.10.15 on windows 7 - installed VIA node-v0.10.15-x86.msi. Downloaded latest UglifyJS2 library. Created batch file with syntax: node "path\to\uglifyjs\bin\uglifyjs" -o "file.min.js" "file.js" Getting error: module.js:340 …
Tauri28
  • 789
  • 1
  • 16
  • 29
3
votes
2 answers

How to use uglifyjs 3 mangle option with toplevel and reserverd?

I have the below command: uglifyjs main.js bar.js -m toplevel reserved=['$','addTo','exports'] -c --source-map -o out.js But it throws error: ERROR: ENOENT: no such file or directory, open 'reserved=[$,addTo,exports]' at Object.fs.openSync…
ace
  • 12,531
  • 35
  • 100
  • 167
3
votes
1 answer

I can't generate a local source-map from a parent directory using UglifyJS2 CLI

I'm trying to minify www/js/app.js to www/js/app.min.js with a source-map: www/js/app.min.js.map. I also want app.min.js to contain the line //# sourceMappingURL=app.min.js.map Is this possible to achieve without using the cd command? So far this is…
3
votes
2 answers

How to load sourcemaps with uglifyjs2 and Ionic?

For my Ionic app, I am using some gulp tasks to minify the Javascript code. Uglifyjs2 minifies the code: gulp.task('uglify', () => { gulp.src(paths.uglify) .pipe(uglify('app.min.js', { outSourceMap: true })) …
Bastian
  • 4,248
  • 5
  • 34
  • 53
3
votes
0 answers

Webpack umd seemingly breaks stacktrace-js functionality

We're trying to use stacktrace-js with the awesome logary-js (my project) but after going through webpack it would seem it doesn't work anymore. Here's the configuration for webpack…
Henrik
  • 9,303
  • 4
  • 49
  • 83
3
votes
1 answer

Uglify after browserify - global variables lost

I am using this command at my package.json: "compile": "browserify js/Initial.js -o build/bundle.js", "postcompile": "uglifyjs --source-map build/game.bundle.js.map --source-map-url game.bundle.js.map -mt -o game.bundle.js build/bundle.js" Inside…
user2426290
  • 231
  • 1
  • 12
3
votes
0 answers

How to generate source maps with Node.js and uglify2 js?

I am using this code function makeJS(pathArray, outfile) { var result = uglifyJS.minify(pathArray, { 'compress': { global_defs: { DEBUG: false } } }); writeFile(outfile,…
omega
  • 30,811
  • 68
  • 188
  • 388