Skip to content

Instantly share code, notes, and snippets.

@anton-ryzhov
Created August 15, 2012 07:33
Show Gist options
  • Save anton-ryzhov/3357389 to your computer and use it in GitHub Desktop.
Save anton-ryzhov/3357389 to your computer and use it in GitHub Desktop.
js include / make
<script src="js/main.js" id="script_include" type="text/javascript"></script>
=>
<script src="js/main.js" id="script_include" type="text/javascript"></script>
<script src="js/less-1.3.0.js" type="text/javascript"></script>
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery-ui.js" type="text/javascript"></script>
user@domain:~/js$ node main.js > out
==
user@domain:~/js$ cat less-1.3.0.js jquery-1.7.2.min.js jquery-ui.js > out
(function(include) {
var prefix, fs, i;
// Import JS in-place into document
if ((typeof document != 'undefined') && document.write && document.getElementById && (prefix = document.getElementById('script_include')))
{
prefix = prefix.src.replace(/[\w\.-]+$/, ''); // Get URI prefix
for (i in include)
document.write('<script src="' + prefix + include[i] + '" type="text/javascript"></script>');
}
// Write to stdout if node.js
if (typeof require == 'function')
{
fs = require('fs');
for (i in include)
process.stdout.write(fs.readFileSync(include[i]));
}
})(['less-1.3.0.js', 'jquery-1.7.2.min.js', 'jquery-ui.js'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment