‘liusuyi’
2023-08-09 161b9318e345c8a0c9cdc133b33a1c759495f323
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// resolve compilers to use.
 
let cached
 
exports.resolveCompiler = function (ctx, loaderContext) {
  if (cached) {
    return cached
  }
 
  // check 2.7
  try {
    const pkg = loadFromContext('vue/package.json', ctx)
    const [major, minor] = pkg.version.split('.')
    if (major === '2' && Number(minor) >= 7) {
      return (cached = {
        is27: true,
        compiler: loadFromContext('vue/compiler-sfc', ctx),
        templateCompiler: undefined
      })
    }
  } catch (e) {}
 
  return (cached = {
    compiler: require('@vue/component-compiler-utils'),
    templateCompiler: loadTemplateCompiler(ctx, loaderContext)
  })
}
 
function loadFromContext(path, ctx) {
  return require(require.resolve(path, {
    paths: [ctx]
  }))
}
 
function loadTemplateCompiler(ctx, loaderContext) {
  try {
    return loadFromContext('vue-template-compiler', ctx)
  } catch (e) {
    if (loaderContext) {
      if (/version mismatch/.test(e.toString())) {
        loaderContext.emitError(e)
      } else {
        loaderContext.emitError(
          new Error(
            `[vue-loader] vue-template-compiler must be installed as a peer dependency, ` +
              `or a compatible compiler implementation must be passed via options.`
          )
        )
      }
    } else {
      throw e
    }
  }
}