Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a little wrapper around Dojo define that uses code taken from RequireJS to calculate the dependencies based on the toString of the definition function. It wraps the current "define" in the global namespace, calculates the dependencies and then call's the wrapped define.</p> <p>defineWrapper.js:</p> <pre><code>// Workaround for the fact that Dojo AMD does not support the Simplified CommonJS Wrapper module definition (function() { var commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g, ostring = Object.prototype.toString; function isArray(it) { return ostring.call(it) === '[object Array]'; } function isFunction(it) { return ostring.call(it) === '[object Function]'; } var oldDefine = define; define = function(name, deps, callback) { //Allow for anonymous functions if (typeof name !== 'string') { //Adjust args appropriately callback = deps; deps = name; name = null; } //This module may not have dependencies if (!isArray(deps)) { callback = deps; deps = []; } //If no name, and callback is a function, then figure out if it a //CommonJS thing with dependencies. if (!deps.length &amp;&amp; isFunction(callback)) { //Remove comments from the callback string, //look for require calls, and pull them into the dependencies, //but only if there are function args. if (callback.length) { callback .toString() .replace(commentRegExp, '') .replace(cjsRequireRegExp, function(match, dep) { deps.push(dep); }); //May be a CommonJS thing even without require calls, but still //could use exports, and module. Avoid doing exports and module //work though if it just needs require. //REQUIRES the function to expect the CommonJS variables in the //order listed below. deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps); } } if(name === null) { return oldDefine(deps, callback); } else { return oldDefine(name, deps, callback); } } })(); </code></pre> <p>How would you use it?</p> <pre><code>&lt;script src="...dojo..."&gt;&lt;/script&gt; &lt;script src="defineWrapper.js"&gt;&lt;/script&gt; &lt;script&gt;require(["some_simplified_commonjs_defined_module"], function(module) { // use module here });&lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload