Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UglifyJS - convert all .js in a folder

I was wondering if anyone could help, I'm attempting to finish off my build process which currently transpiles es6 > es5 using babel, After that has completed I want to use uglifyJS to recursively minify all my .js files using just NPM scripts (no grunt or gulp please).

What I desire;

  • Convert all .js in folder to es5
  • Minify all .js files in a given folder using uglify
  • Create source maps
  • Copy out to a new folder

My current setup;

  • Converts all .js to es5
  • Minify all es5 .js files (However no sourcemaps are created, also the es5 js files are replaced as theres no support to move to another folder)

I've tried: https://www.npmjs.com/package/recursive-uglifyjs and https://www.npmjs.com/package/uglifyjs-folder but these both seem unable to perform the build steps I need

Here is my package.json scripts section

   "babel": "babel js_uncompiled --out-dir js_uncompiled/es5 --source-maps  && npm run npm:uglify",
    "build": "npm run babel",
    "uglify": "recursive-uglifyjs js_uncompiled/es5"

You can find a link to my full package.json here : http://pastebin.com/4UHZ1SGM

Thanks

like image 746
does_not_compute Avatar asked Jul 11 '16 14:07

does_not_compute


1 Answers

EDITED: included info from comments

So, now uglifyjs-folder has the option of passing a config file so you can run all uglify's commands, but on a whole folder (and you can transpile to ES5 using harmony - as stated in comments).

Note this is better than doing so manually with cat or other shell commands, since uglifyjs-folder can generate a single output file (concatenated) and is simpler to use.

Run uglifyjs-folder "%CD%" --config-file "uglify.config.json" --output "folder" -e where the config file (in the root folder of project) contains for example (not all options needed):

{ "compress": true, "mangle": true, "sourceMap": { "base": "input/path/", "content": "input/sourcemap", "filename": "{file}.min.js", "includeSources": true, "root": "original/source/path", "url": "source/path" } }

Obs.: currently there is one open issue by myself because source-mapping is resulting in error. Once the issue is solved I will update my answer here.

UPDATE: ok, issue solved, version 1.5 released! Code above updated

like image 99
Bernardo Dal Corno Avatar answered Nov 12 '22 18:11

Bernardo Dal Corno