Skip to content
Browse files

Added minification via uglify-js; fixes #19

  • Loading branch information...
1 parent 39e2aaa commit 77e0ad123d5911ac1ed80d030e866a2373fd8adb Daniel Yoder committed
Showing with 22 additions and 9 deletions.
  1. +4 −4 doc/USAGE
  2. +3 −2 package.json
  3. +14 −2 src/ark.coffee
  4. +1 −1 src/cli.coffee
View
8 doc/USAGE
@@ -24,7 +24,7 @@ OPTIONS
--static, -z Do static dependency analysis, beginning with the main entry
point specified in the root package.json file.
- --uglify, -u Uglify (minimize) the code when packaging.
+ --minify, -m Minifies (using uglify-js) the code when packaging.
--extensions, -x Include files with the specified extensions. Multiple
extensions can be specified, separated by commas.
@@ -37,13 +37,13 @@ To use static analysis to generate a manifest of what will be packaged up:
Then you can package up the manifest like this:
- ark package --uglify < manifest.txt > web/js/web-api.js
+ ark package --minify < manifest.txt > web/js/web-api.js
Or, in one step, without static analysis (just packaging all your source files up):
- ark package --uglify --source cs/lib/web > web/js/web-api.js
+ ark package --minify --source cs/lib/web > web/js/web-api.js
Or, automagically picking up and compiling CoffeeScript:
- ark package --uglify web/js/web-api.js --source cs/src/web > web/js/web-api.js
+ ark package --minify web/js/web-api.js --source cs/src/web > web/js/web-api.js
View
5 package.json
@@ -1,6 +1,6 @@
{
"name": "ark",
- "version": "0.1.3",
+ "version": "0.1.4",
"description": "Packages code for the browser as Node modules.",
"main": "lib/ark.js",
"bin": {
@@ -27,6 +27,7 @@
"eco": "1.1.x",
"fibers": "0.6.x",
"glob": "3.1.x",
- "optimist": "0.3.x"
+ "optimist": "0.3.x",
+ "uglify-js": "1.3.x"
}
}
View
16 src/ark.coffee
@@ -7,6 +7,14 @@ Future = require "fibers/future"
Eco = require "eco"
CoffeeScript = require "coffee-script"
+minify = (->
+ {parser,uglify} = require "uglify-js"
+ (code) ->
+ ast = parser.parse code
+ ast = uglify.ast_mangle ast
+ ast = uglify.ast_squeeze ast
+ uglify.gen_code ast
+)()
beautify = (->
_beautify = require "./beautify"
@@ -152,7 +160,7 @@ index = (manifest) ->
code = (filesystem) ->
template = read("#{__dirname}/templates/node.js")
- beautify render template, filesystem
+ render template, filesystem
Ark =
@@ -169,7 +177,11 @@ Ark =
else
manifest options
- print code index manifest
+ print if options.minify
+ minify code index manifest
+ else
+ beautify code index manifest
+
run_as_fiber = (fn) ->
->
View
2 src/cli.coffee
@@ -28,7 +28,7 @@ for key,value of argv
options =
source: argv.s or argv.source
static: argv.z or argv.static
- uglify: argv.u or argv.uglify
+ minify: argv.m or argv.minify
extensions: argv.x or argv.extensions
# if a source directory is specified, use that; otherwise assume we'll read

0 comments on commit 77e0ad1

Please sign in to comment.
Something went wrong with that request. Please try again.