Blame view

node_modules/vue-loader/lib/template-compiler/preprocessor.js 873 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  // loader for pre-processing templates with e.g. pug
  
  const cons = require('consolidate')
  const loaderUtils = require('loader-utils')
  
  module.exports = function (content) {
    this.cacheable && this.cacheable()
    const callback = this.async()
    const opt = loaderUtils.getOptions(this) || {}
  
    if (!cons[opt.engine]) {
      return callback(
        new Error(
          "Template engine '" +
            opt.engine +
            "' " +
            "isn't available in Consolidate.js"
        )
      )
    }
  
    // allow passing options to the template preprocessor via `template` option
    if (this.options.__vueOptions__) {
      Object.assign(opt, this.options.__vueOptions__.template)
    }
  
    // for relative includes
    opt.filename = this.resourcePath
  
    cons[opt.engine].render(content, opt, (err, html) => {
      if (err) {
        return callback(err)
      }
      callback(null, html)
    })
  }