9

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Now uglifyjs-folder can transpile to ES5 using harmony.
Thanks @PranavSingh, updating my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.