selector.js 917 B

12345678910111213141516171819202122
  1. // this is a utility loader that takes a *.vue file, parses it and returns
  2. // the requested language block, e.g. the content inside <template>, for
  3. // further processing.
  4. const path = require('path')
  5. const parse = require('./parser')
  6. const loaderUtils = require('loader-utils')
  7. module.exports = function (content) {
  8. this.cacheable()
  9. const query = loaderUtils.getOptions(this) || {}
  10. const context = (this._compiler && this._compiler.context) || this.options.context || process.cwd()
  11. let filename = path.basename(this.resourcePath)
  12. filename = filename.substring(0, filename.lastIndexOf(path.extname(filename))) + '.vue'
  13. const sourceRoot = path.dirname(path.relative(context, this.resourcePath))
  14. const parts = parse(content, filename, this.sourceMap, sourceRoot)
  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. }