Skip to content

Instantly share code, notes, and snippets.

@rmanalan
Created September 27, 2010 18:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmanalan/599562 to your computer and use it in GitHub Desktop.
Save rmanalan/599562 to your computer and use it in GitHub Desktop.
Psuedo code for a JS/CSS packager for static HTML apps
//manifest.js: defines the grouping of js/css
var $packager.assets = {
'app.js': [
{ name:'jquery.js', wait:true },
{ name:'sfasdf.js', wait:true },
{ name:'fasdt.js', wait:true }
],
'app.css': [
'blueprint.css',
'style.css'
]
}
// config.js: defines the environment you're currently in.
// if mode == development, non-minified/non-compressed js files are loaded,
// else if mode == production, only the minified/compressed version is loaded
var $packager.config = { mode: 'development' }
//index.html
<script src="config.js"></script>
<script src="package.js"></script>
<script>
$packager.use('app.js')
</script>
// $packager.use is how you load your js. Underneath it uses LABjs
$packager.use = function(scriptName){
if($packager.config.mode=='production'){
$LAB.script(scriptName)
} else {
for(var script in $packager.assets[scriptName]) {
if(script.wait) $LAB.script(script.name).wait();
else $LAB.script(script.name);
}
}
}
// of course we need a CLI based builder that will spit out
// compressed/minified versions of the js/css defined in
// the manifest.js
//
// $ node build.js manifest.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment