require-like support to the frontend
Let's start with a small project:
lib-shared/shuffle.js lib-server/server.js lib-client/main.js
And some modules in
package.json for our Node.js server:
"express": "3.0.2", "amdefine": "0.0.2", "underscore": "1.4.2"
Our function looks like a basic Node.js backend function with a dependency on underscore.
Use amdefine boilerplate to make
define available to
Node.js in "lib-shared/shuffle.js":
Let's create a JSON REST API in "lib-server/server.js" with our new function.
Now, on to the browser...
RequireJS is an AMD-compatible script loader with features including:
Let's start with a main insertion point in "index.html".
From here on, there are no other script includes!
Configure "lib-client/main.js" to point to our client libraries.
From here, we can
see it in the demo.
At Curiosity Media, we use RequireJS for shared code for:
Beyond this, RequireJS offers a lot more functionality than we've seen here today for managing your entire frontend asset collection.