|
| 1 | +define('util',[],function () { |
| 2 | + function upper(text) { |
| 3 | + return text.toUpperCase(); |
| 4 | + }; |
| 5 | + |
| 6 | + return upper; |
| 7 | +}); |
| 8 | + |
| 9 | +if (typeof define === 'function' && define.amd) { |
| 10 | + define('converter',['util'], function (util) { |
| 11 | + |
| 12 | + return { |
| 13 | + version: '2', |
| 14 | + convert: function (text) { |
| 15 | + return util(text); |
| 16 | + } |
| 17 | + }; |
| 18 | + }); |
| 19 | +}; |
| 20 | +define('plug',['converter'], function (converter) { |
| 21 | + var buildMap = {}; |
| 22 | + |
| 23 | + function jsEscape(content) { |
| 24 | + return content.replace(/(['\\])/g, '\\$1') |
| 25 | + .replace(/[\f]/g, "\\f") |
| 26 | + .replace(/[\b]/g, "\\b") |
| 27 | + .replace(/[\n]/g, "\\n") |
| 28 | + .replace(/[\t]/g, "\\t") |
| 29 | + .replace(/[\r]/g, "\\r"); |
| 30 | + } |
| 31 | + |
| 32 | + return { |
| 33 | + version: '1', |
| 34 | + load: function (name, require, onLoad, config) { |
| 35 | + var converted = converter.convert(name); |
| 36 | + buildMap[name] = converted; |
| 37 | + onLoad(converted); |
| 38 | + }, |
| 39 | + |
| 40 | + write: function (pluginName, moduleName, write, data) { |
| 41 | + if (moduleName in buildMap) { |
| 42 | + var content = jsEscape(buildMap[moduleName]); |
| 43 | + write("define('" + pluginName + "!" + moduleName + |
| 44 | + "', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n"); |
| 45 | + } |
| 46 | + } |
| 47 | + }; |
| 48 | +}); |
| 49 | + |
| 50 | + |
| 51 | +define('plug!shouldbeuppercasetext', function () { /* name: plug path: main-builtPluginFirst.js */ return 'SHOULDBEUPPERCASETEXT';}); |
| 52 | + |
| 53 | +require(['plug', 'converter', 'plug!shouldbeuppercasetext'], |
| 54 | +function (plug, converter, text) { |
| 55 | + console.log('plugin version: ' + plug.version); |
| 56 | + console.log('converter version: ' + converter.version); |
| 57 | + console.log('converted text: ' + text); |
| 58 | +}); |
| 59 | + |
| 60 | +define("main", function(){}); |
| 61 | + |
0 commit comments