Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including grunt-amd-wrap with all npm packages installed. Try it out:

grunt-amd-wrap lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

require("grunt/package.json"); // grunt is a peer dependency. // require("grunt-amd-wrap/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

grunt-amd-wrap v1.0.1

Grunt task to wrap CommonJS files in `define(function (require, exports, module) { ... })`.

Wrap CommonJS in AMD via Grunt

This is a Grunt plugin to wrap your CommonJS modules into the simplified CommonJS wrapper format, i.e.:

define(function (require, exports, module) {
    // your CommonJS code here
});

It's based on amd-wrap, if you want this functionality outside of a Grunt plugin.

Usage

It doesn't take any options. You just configure it to map each source file to a destination file, and you end up with some wrapped-up-as-AMD modules. I'll give a few examples here, each under a different build target:

grunt.loadNpmTasks("grunt-amd-wrap");

grunt.initConfig({
    amdwrap: {
        onlyOneFile: {
            { src: "lib/my-module.js", dest: "artifacts/amd/my-module.js" }
        },
        aFewFilesManually: {
            { src: "lib/my-module.js", dest: "artifacts/amd/my-module.js" },
            { src: "lib/helper-module.js", dest: "artifacts/amd/helper-module.js" }
        },
        usingDynamicExpansion: {
            expand: true,
            cwd: "lib/",
            src: ["*.js"],
            dest: "artifacts/amd/"
        }
    }
});

You'll probably want to use the last pattern most of the time. It's based on Grunt's dynamic mapping expansion feature.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free