Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added ability to control UglifyJS options #20

Open
wants to merge 1 commit into from

1 participant

@kernel-io

I've added the ability to change the uglifyJS options from within the config.json file. I've added an example within the example config.json file.

I don't know how useful this will be to you all, but I needed to be able to specify certain options (making certain variable names exempt from mangling).

Any suggestions, don't hesitate to ask. Also, I hope my coding style is not out of place.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2012
  1. @kernel-io
This page is out of date. Refresh to see the latest.
Showing with 54 additions and 8 deletions.
  1. +14 −1 examples/config_json/config.json
  2. +40 −7 lib/smoosh/index.js
View
15 examples/config_json/config.json
@@ -6,8 +6,21 @@
"base": [ "./src/header.js", "./src/script.js" ],
"secondary": [ "./src/foo.js", "./src/foo.bar.js", "./src/foo.bar.baz.js" ]
},
+ "UGLIFYJS_OPTS": {
+ "mangle": true,
+ "squeeze": true,
+ "mangle_options": {
+ "except" : ["ExampleA", "Example B", "Example C"]
+ },
+ "squeeze_options": {
+ "make_seqs": false
+ },
+ "gen_code_options": {
+ "beautify": true
+ }
+ },
"CSS": {
"DIST_DIR": "dist",
"styles": ["./src/bar.css", "./src/foo.css"]
}
-}
+}
View
47 lib/smoosh/index.js
@@ -7,6 +7,7 @@ var fs = require('fs')
, rimraf = require('rimraf')
, sqwish = require('sqwish');
+
/**
* SOME DUMB HELPERS
*/
@@ -373,16 +374,48 @@ var _build = {
},
uglify: function (file, file_contents) {
+ try {var conf = _config.config.UGLIFYJS_OPTS;} catch(e){}
var tok = uglifyJs.parser.tokenizer(file_contents)
, c = tok();
_files.JAVASCRIPT_MIN[file] = this.showCopyright(c.comments_before) || '';
-
- var ast = uglifyJs.parser.parse(file_contents);
- ast = uglifyJs.uglify.ast_mangle(ast);
- ast = uglifyJs.uglify.ast_squeeze(ast);
-
- _files.JAVASCRIPT_MIN[file] += uglifyJs.uglify.gen_code(ast);
+ var ast;
+ if (conf) {
+ if (conf.hasOwnProperty('strict_semicolons') && conf.strict_semicolons) {
+ ast = uglifyJs.parser.parse(file_contents,true);
+ } else {
+ ast = uglifyJs.parser.parse(file_contents);
+ }
+
+ if (conf.hasOwnProperty('mangle') && conf.mangle) {
+ if (conf.hasOwnProperty('mangle_options')) {
+ ast = uglifyJs.uglify.ast_mangle(ast,conf.mangle_options);
+ } else {
+ ast = uglifyJs.uglify.ast_mangle(ast);
+ }
+ }
+
+ if (conf.hasOwnProperty('squeeze') && conf.squeeze) {
+ if (conf.hasOwnProperty('squeeze_options')) {
+ ast = uglifyJs.uglify.ast_squeeze(ast,conf.squeeze_options);
+ } else {
+ ast = uglifyJs.uglify.ast_squeeze(ast);
+ }
+ }
+
+ if (conf.hasOwnProperty('lift_variables') && conf.lift_variables) {
+ ast = uglifyJs.uglify.ast_lift_variables(ast);
+ }
+
+ if (conf.hasOwnProperty('gen_code_options')) {
+ _files.JAVASCRIPT_MIN[file] += uglifyJs.uglify.gen_code(ast, conf.gen_code_options);
+ }
+ } else {
+ ast = uglifyJs.parser.parse(file_contents);
+ ast = uglifyJs.uglify.ast_mangle(ast);
+ ast = uglifyJs.uglify.ast_squeeze(ast);
+ _files.JAVASCRIPT_MIN[file] += uglifyJs.uglify.gen_code(ast);
+ }
this.writeFile(this.getBuildPath(file, 'JAVASCRIPT', true), _files.JAVASCRIPT_MIN[file]);
_write.built('a minified file with uglifyJs', file);
@@ -707,4 +740,4 @@ for (var key in _API) {
for (var key in _interface) {
module.exports[key] = _interface[key];
-}
+}
Something went wrong with that request. Please try again.