UNPKG

583 BJavaScriptView Raw
1const parseComponent = require('./parser')
2const loaderUtils = require('loader-utils')
3
4module.exports = function (content) {
5 this.cacheable()
6 const mpx = this._compilation.__mpx__
7 if (!mpx) {
8 return content
9 }
10 const mode = mpx.mode
11 const defs = mpx.defs
12 const query = loaderUtils.getOptions(this) || {}
13 const filePath = this.resourcePath
14 const parts = parseComponent(content, filePath, this.sourceMap, mode, defs)
15 let part = parts[query.type] || {}
16 if (Array.isArray(part)) {
17 part = part[query.index]
18 }
19 this.callback(null, part.content, part.map)
20}