mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 00:13:10 -07:00
Upgrade uglify and simplify usage
- Upgrade to the most recent version of uglify - Use the `UglifyJS.minify(code)` helper which does exactly what we want
This commit is contained in:
parent
ee03e7cd78
commit
318c5f7ba6
4 changed files with 25 additions and 13 deletions
12
server.js
12
server.js
|
@ -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');
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue