amdefine: Use AMD Modules on Node.js
Join the DZone community and get the full member experience.
Join For FreeJames Burke’s npm module amdefine lets you write AMD modules [1] that also work on Node.js. To do so, you need to perform the following steps:
- Install amdefine:
npm install amdefine
Optional: install into your project by making it a dependency in your package.json. - Prefix your AMD with the following line (split into three lines below):
if (typeof define !== 'function') { var define = require('amdefine')(module) }
That line will be removed when packaging your AMDs for deployment via the RequireJS optimizer.
If you don’t want to force Node.js users of your module to install amdefine, there are alternatives [2] for writing AMDs that also work on Node.js. But they have other disadvantages.
References:
Asynchronous module definition
Node.js
Published at DZone with permission of Axel Rauschmayer, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments