Blame view

node_modules/vue-loader/lib/selector.js 917 Bytes
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  // this is a utility loader that takes a *.vue file, parses it and returns
  // the requested language block, e.g. the content inside <template>, for
  // further processing.
  
  const path = require('path')
  const parse = require('./parser')
  const loaderUtils = require('loader-utils')
  
  module.exports = function (content) {
    this.cacheable()
    const query = loaderUtils.getOptions(this) || {}
    const context = (this._compiler && this._compiler.context) || this.options.context || process.cwd()
    let filename = path.basename(this.resourcePath)
    filename = filename.substring(0, filename.lastIndexOf(path.extname(filename))) + '.vue'
    const sourceRoot = path.dirname(path.relative(context, this.resourcePath))
    const parts = parse(content, filename, this.sourceMap, sourceRoot)
    let part = parts[query.type]
    if (Array.isArray(part)) {
      part = part[query.index]
    }
    this.callback(null, part.content, part.map)
  }