uglify-register

The require hook will bind itself to node's require and automatically uglify files on the fly.

MIT License

Downloads
175
Stars
11
Committers
1

uglify-register Version Badge

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:

require('uglify-register');

With custom uglify options:

require('uglify-register/api')({
	uglify: {
		mangle: true // for example
	},
});

With custom file extensions:

require('uglify-register/api')({
	extensions: ['.js', '.jsx'], // defaults to just ".js" if omitted
});

Excluding files that match provided regular expressions:

require('uglify-register/api')({
	exclude: [
		/\/node_modules\/, // third-party code
		/\/test\//, // code under a "test" dir
		\/some-special-file.js$\/, // some file
	],
});

All options can of course be combined.

Tests

Simply clone the repo, npm install, and run npm test