Skip to content

Instantly share code, notes, and snippets.

@pyadav
Forked from mdellanoce/app.js
Last active August 29, 2015 14:27
Show Gist options
  • Save pyadav/9cd85931617c96fdf416 to your computer and use it in GitHub Desktop.
Save pyadav/9cd85931617c96fdf416 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