Use this require hook to uglify JS files on-the-fly.
This is particularly useful when trying to replicate production minification effects in a dev or test environment.
Not recommended for a production environment, like all require hooks.
Install
npm install --save-dev uglify-register
Usage
With no extra uglify options; only for the .js
extension; for all files:
;
With custom uglify options:
uglify: mangle: true // for example ;
With custom file extensions:
extensions: '.js' '.jsx' // defaults to just ".js" if omitted;
Excluding files that match provided regular expressions:
exclude: /\/node_modules\/, // third-party code /\/test\// // code under a "test" dir \/some-special-filejs$\/ // some file ;
All options can of course be combined.
Tests
Simply clone the repo, npm install
, and run npm test