Skip to content

Commit

Permalink
Upgrade uglify and simplify usage
Browse files Browse the repository at this point in the history
- Upgrade to the most recent version of uglify
- Use the `UglifyJS.minify(code)` helper which does exactly what we want
  • Loading branch information
seejohnrun committed Nov 1, 2017
1 parent ee03e7c commit 318c5f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
22 changes: 19 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"winston": "0.6.2",
"redis-url": "0.1.0",
"redis": "0.8.1",
"uglify-js": "1.3.3",
"uglify-js": "3.1.6",
"busboy": "0.2.4",
"pg": "4.1.1"
},
Expand Down
12 changes: 4 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var http = require('http');
var fs = require('fs');

var uglify = require('uglify-js');
var winston = require('winston');
var connect = require('connect');
var route = require('connect-route');
Expand Down Expand Up @@ -54,19 +55,14 @@ else {

// Compress the static javascript assets
if (config.recompressStaticAssets) {
var jsp = require('uglify-js').parser;
var pro = require('uglify-js').uglify;
var list = fs.readdirSync('./static');
for (var j = 0; j < list.length; j++) {
var item = list[j];
var orig_code, ast;
if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) {
var dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3);
orig_code = fs.readFileSync('./static/' + item, 'utf8');
ast = jsp.parse(orig_code);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
fs.writeFileSync('./static/' + dest, pro.gen_code(ast), 'utf8');
var orig_code = fs.readFileSync('./static/' + item, 'utf8');

fs.writeFileSync('./static/' + dest, uglify.minify(orig_code).code, 'utf8');
winston.info('compressed ' + item + ' into ' + dest);
}
}
Expand Down
2 changes: 1 addition & 1 deletion static/application.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 318c5f7

Please sign in to comment.