UNPKG

weex-loader

Version:
31 lines (24 loc) 869 B
'use strict'; var _parser = require('./parser'); module.exports = function (source, map) { this.cacheable && this.cacheable(); var callback = this.async(); (0, _parser.parseScript)(source).then(function (_ref) { var parsed = _ref.parsed; var requireList = parsed.match(/require\([^()]+?\)/g); if (requireList && requireList.length > 0) { requireList = requireList.filter(function (str) { if (str.indexOf('@weex-module') > 0) { parsed = parsed.replace(str, str.replace('require', '__weex_require__')); return true; } return false; }).join('\n'); } var result = 'module.exports = function(module, exports, __weex_require__){' + parsed + '}'; result += '\n/* generated by weex-loader */\n'; callback(null, result, map); }).catch(function (e) { callback(e, ''); }); };