| import { |
| parseScript |
| } from './parser' |
| |
| module.exports = function (source, map) { |
| this.cacheable && this.cacheable() |
| |
| const callback = this.async() |
| |
| parseScript(source) |
| .then(({ |
| parsed |
| }) => { |
| let requireList = parsed.match(/require\([^()]+?\)/g) |
| |
| if (requireList && requireList.length > 0) { |
| requireList = requireList.filter(str => { |
| if (str.indexOf('@weex-module') > 0) { |
| parsed = parsed.replace(str, str.replace('require', '__weex_require__')) |
| return true |
| } |
| return false |
| }).join('\n') |
| } |
| |
| let result = `module.exports = function(module, exports, __weex_require__){${parsed}}` |
| result += '\n/* generated by weex-loader */\n' |
| callback(null, result, map) |
| }).catch(e => { |
| callback(e, '') |
| }) |
| } |