amd-wrapper v0.1.3
amd-wrapper
A node utility to simple wrapping CommonJs file to AMD. Optionally, resolving the require module id to ensure the require id can work in AMD environment.
How to use
Install
npm install amd-wrapper --saveUsage
var amdWrap = require('amd-wrapper');
// only simple wrapping like this
// define(function (require, exports, module) { ... })
var result = amdWrap('code');
result = amdWrap('code', { // resolve require id
resolveRequire: true,
filePath: 'a/b.js',
requireConfig: {
baseUrl: 'src',
packages: []
},
projectRoot: 'root absolute path',
componentDirName: 'dep'
});Options
code
string: the code to transformoptions
Objectoptional: the options to transformoptions.resolveRequire
booleanoptional: whether resolve require module id to ensure the amd module loader require work, by default falseoptions.filePath
string: the file path host the codeoptions.requireConfig
string|function():Object: the amd require configoptions.projectRoot
string: the project root absolute path, by default the execute directory currentlyptions.componentDirName
stringoptional: the directory to install the package to resolve, by defaultnode_modulesoptions.extensions
Array.<string>optional: array of file extensions to search the require module in order, by default,['.js']checkUMD
booleanoptional: whether checkUMDmodule style, if the code existsUMDdefine, the transform will ignore, by defaultfalseoptions.debug
booleanoptional: whether to output resolve fail module info, by defaultfalse