Skip to content

Instantly share code, notes, and snippets.

@mdellanoce
Created December 9, 2011 22:21
Show Gist options
  • Save mdellanoce/1453578 to your computer and use it in GitHub Desktop.
Save mdellanoce/1453578 to your computer and use it in GitHub Desktop.
Auto-optimization with Express and RequireJS
var express = require('express'),
requirejs = require('requirejs'),
app = module.exports = express.createServer();
app.configure('development', function(){
// Use development version of static files
app.use(express.static(__dirname + '/public'));
});
app.configure('production', function(){
// Optimize the javascript in the public folder and
// copy it to the public_build folder.
requirejs.optimize({
appDir: "public/",
baseUrl: "javascripts",
dir: "public_build",
modules: [
{
name: "main"
}
]
}, function() {
console.log('Successfully optimized javascript');
});
// Use minified static files
app.use(express.static(__dirname + '/public_build'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment