amdefine is a JavaScript module that allows the Asynchronous Module Definition (AMD) `define()` API to operate within a Node.js environment without requiring a full AMD loader. This enables developers to create modules using the AMD format, primarily designed for browser environments, and subsequently run them in Node.js applications. The package, currently at version 1.0.1, has not seen updates in approximately nine years and is considered abandoned. It provides a shim for `define` via a conditional `require` snippet placed at the top of each AMD module, or through an `amdefine/intercept` module that automatically injects the shim globally. While AMD is largely superseded by CommonJS and ES Modules for modern Node.js development, amdefine remains relevant for integrating or migrating existing AMD codebases into a Node.js context, acting as a compatibility layer with minimal overhead.
npm install amdefineVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining and consuming AMD modules using `amdefine` in a Node.js application, including the conditional `define` snippet and inter-module dependencies.
For library code or scenarios requiring more control, avoid `amdefine/intercept`. Instead, use the conditional `if (typeof define !== 'function') { var define = require('amdefine')(module) }` snippet at the top of each individual AMD module.Maintain the exact basic structure of the conditional `define` snippet to ensure proper optimization and code stripping by RequireJS.
For new projects, consider using ES Modules or CommonJS for module definition. `amdefine` is best suited for maintaining or integrating existing AMD-based codebases within Node.js.
Ensure the conditional snippet `if (typeof define !== 'function') { var define = require('amdefine')(module) }` is present and correctly placed at the very top of your AMD module file, or that `require('amdefine/intercept')` is executed early in your application's entry point.Use the CommonJS-wrapped AMD format by declaring `define(function (require) { ... })` to get `require` as an argument, or include 'require' in your dependency array: `define(['require', 'dependency'], function(require, dependency) { ... })`.