Skip to content

Commit

Permalink
Working build with AMD stripping and minification.
Browse files Browse the repository at this point in the history
  • Loading branch information
SlexAxton committed Nov 8, 2012
1 parent 788487b commit fb9209d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Modernizr 3.0.0pre (Custom Build) | MIT & BSD */
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ rm -rf dist
mkdir dist
cp build/src/modernizr-build.js dist/modernizr-build.js
rm -rf build
node stripdefine.js
node processbuild.js
m=$(stat -f "%z" dist/modernizr-build.min.js)
gzip -nfc --best dist/modernizr-build.min.js > dist/modernizr-build.min.js.gz
g=$(stat -f "%z" dist/modernizr-build.min.js.gz)
rm -f dist/modernizr-build.min.js.gz
echo "$m bytes minified, $g bytes gzipped"
11 changes: 11 additions & 0 deletions modular-build-min.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html class="no-js" lang=en>
<head>
<title>Modular Modernizr Demo Page</title>
</head>
<body>
Console, yo.

<script src="dist/modernizr-build.min.js"></script>
</body>
</html>
14 changes: 0 additions & 14 deletions modular-build.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,5 @@
Console, yo.

<script src="dist/modernizr-build.js"></script>
<!-- After a build, you could try this
<script src="src/require.js"></script>
<script>
require.config({
baseUrl : 'src/',
paths : {
'test' : '../feature-detects'
}
});
</script>
<script src="src/modernizr-init.js"></script>
-->
</body>
</html>
3 changes: 0 additions & 3 deletions modular.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@
});
</script>
<script src="src/modernizr-init.js"></script>
<!-- After a build, you could try this
<script src="dist/modernizr-build.js"></script>
-->
</body>
</html>
20 changes: 20 additions & 0 deletions processbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var fs = require('fs');

var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;

var mod = fs.readFileSync(__dirname + '/dist/modernizr-build.js', 'utf8');
var license = fs.readFileSync(__dirname + '/LICENSE', 'utf8');

mod = mod.replace('define("modernizr-init",[], function(){});', '');
mod = license + "\n;(function(window, document, undefined){\n" + mod + "\n})(this, document);";

fs.writeFileSync(__dirname + '/dist/modernizr-build.js', mod, 'utf8');

var ast = jsp.parse(mod); // parse code and get the initial AST
ast = pro.ast_lift_variables(ast);
ast = pro.ast_mangle(ast, {except : ["Modernizr"]}); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
var final_code = pro.gen_code(ast);

fs.writeFileSync(__dirname + '/dist/modernizr-build.min.js', license + ";" + final_code, 'utf8');

0 comments on commit fb9209d

Please sign in to comment.