Skip to content

Commit

Permalink
almost successfully stripping AMD wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
SlexAxton committed Nov 8, 2012
1 parent fe859d0 commit 832a524
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
28 changes: 24 additions & 4 deletions app.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@
"dir" : "build/", // and copy them to this dir, then optimize
"baseUrl" : "src/",
"optimize" : "none",
"optimizeCss" : "none",
"paths" : {
"test" : "../feature-detects"
},
modules : [
{
"name" : "modernizr-build",
"include" : ["modernizr-init"],
"create" : true
"name" : "modernizr-build",
"include" : ["modernizr-init"],
"create" : true
}
],
onBuildWrite: function (id, path, contents) {
if ((/define\(.*?\{/).test(contents)) {
//Remove AMD ceremony for use without require.js or almond.js
contents = contents.replace(/define\(.*?\{/, '');

if ( contents.match(/return.*[^return]*$/) ) {
//remove last return statement and trailing })
contents = contents.replace(/return.*[^return]*$/,'');
}
else {
contents = contents.replace(/\}\);\s*?$/,'');
}
}
]
else if ((/require\([^\{]*?\{/).test(contents)) {
contents = contents.replace(/require[^\{]+\{/, '');
contents = contents.replace(/\}\);\s*$/,'');
}
return contents;
}
})
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ rm -rf dist
mkdir dist
cp build/src/modernizr-build.js dist/modernizr-build.js
rm -rf build
node stripdefine.js
25 changes: 25 additions & 0 deletions modular-build.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html class="no-js" lang=en>
<head>
<title>Modular Modernizr Demo Page</title>
</head>
<body>
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>
6 changes: 6 additions & 0 deletions stripdefine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var fs = require('fs');

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

mod = mod.replace('define("modernizr-init", function(){});', '');
fs.writeFileSync(__dirname + '/dist/modernizr-build.js', ";(function(window, document, undefined){\n" + mod + "\n})(this, document);", 'utf8');

0 comments on commit 832a524

Please sign in to comment.