Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Added support for res._no_mangle (fix #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
breezewish committed Jul 8, 2014
1 parent a288415 commit 8062b1c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ express.static.mime.define(
app.use(minify());
```

## Disable mangle for a specific response

use `response._no_mangle = true`.

Generally you may need this if you are using AngularJs:

```javascript
app.use(function(req, res, next)
{
// do not mangle -angular.js files
if (/-angular\.js$/.test(req.url)) {
res._no_mangle = true;
}
next();
});
app.use(minify());
```

## Disable minify or cache for a specific response

If you don't want to minify a specific response, just use: `response._no_minify = true`. Notice that this would also disabling CoffeeScript/SCSS/LESS/Stylus parsing for this response.
Expand Down Expand Up @@ -190,9 +208,13 @@ If you are using `cluster`, it is strongly recommended to enable file cache.

# Change log

0.0.9

- Added support for `res._no_mangle` [#10](https://github.com/breeswish/express-minify/pull/10)

0.0.8

- Remove options of `whitelist` and `blacklist`
- Removed options of `whitelist` and `blacklist`

- Added support for `res._no_cache` [#5](https://github.com/breeswish/express-minify/issues/5)

Expand Down
17 changes: 17 additions & 0 deletions examples/angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var minify = require('express-minify');
var express = require('express');
var app = express();

app.use(function(req, res, next)
{
// do not mangle angular JavaScript files
if (/-angular\.js$/.test(req.url)) {
res._no_mangle = true;
}
next();
});

app.use(minify());
app.use(express.static(__dirname + '/static'));

app.listen(8080);
16 changes: 12 additions & 4 deletions minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ function precompileError(err, type)
return JSON.stringify(err);
}

function minifyIt(type, content, callback)
function minifyIt(type, options, content, callback)
{
if (typeof callback != 'function')
return;

switch(type)
{
case TYPE_JS:
callback(uglifyjs.minify(content, {fromString: true}).code);
var opt = {fromString: true};
if (options.no_mangle) {
opt.mangle = false;
}
callback(uglifyjs.minify(content, opt).code);
break;
case TYPE_CSS:
callback(cssmin(content));
Expand Down Expand Up @@ -76,7 +80,11 @@ function minifyIt(type, content, callback)
break;
case TYPE_COFFEE:
var js = coffee.compile(content);
callback(uglifyjs.minify(js, {fromString: true}).code);
var opt = {fromString: true};
if (options.no_mangle) {
opt.mangle = false;
}
callback(uglifyjs.minify(js, opt).code);
break;
default:
callback(content);
Expand Down Expand Up @@ -316,7 +324,7 @@ module.exports = function express_minify(options)
break;
default:
// cache miss
minifyIt(type, buffer.toString(encoding), function(minized) {
minifyIt(type, { no_mangle: _this._no_mangle }, buffer.toString(encoding), function(minized) {
if (_this._no_cache) {
// do not save cache for this response
end.call(_this, minized, 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Breezewish",
"description": "express-minify is an express middleware that automatically minify your javascript and css files.",
"homepage": "https://github.com/breeswish/express-minify",
"version": "0.0.7",
"version": "0.0.9",
"main": "minify.js",
"keywords": [
"uglify",
Expand Down

0 comments on commit 8062b1c

Please sign in to comment.