Connect middleware for RequireJS compiling

npm install requirejs-middleware
3 downloads in the last day
137 downloads in the last week
402 downloads in the last month


Middleware for Express that runs the RequireJS optimizer on demand. Production-ready and used by Mozilla Popcorn Maker.


npm install requirejs-middleware


var express = require("express"),
    path = require("path"),
    requirejsMiddleware = require("requirejs-middleware");

var app = express();

  src: path.join(__dirname + "/public"),
  dest: path.join(__dirname + "/build"),
  build: true,
  debug: true,
  modules: {
    "/main.js": {
      baseUrl: path.join(__dirname + "/public"),
      include: "main"
app.use(express.static(path.join(__dirname + "/build")));
app.use(express.static(path.join(__dirname + "/public")));


See the full example in examples/almond/server.js.


  • src - Source directory containing the RequireJS modules. Required
  • dest - Destination directory to write built RequireJS modules to. Required
  • build - Optimize modules. When disabled, the module will be served up unchanged. Default false
  • once - Optimize modules once. Recommended for production deployments. Default false
  • debug - Output debugging information on the console. Default false
  • modules - Object containing module paths and RequireJS optimizer options. Required
    • string - Path to RequireJS module
      • baseUrl - All modules are located relative to this path. Required
      • include - Include this module in the output file. Required if you are optimizing with almond.
      • name - Name of the module to optimize first. Defaults to almond
npm loves you