cnf
2025-05-10 386fa0eca75ddc88165f9b73038f2a2239e1072e
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const fs = require('fs')
const path = require('path')
 
const {
  pathToGlob
} = require('@dcloudio/uni-cli-shared/lib/util')
 
let partialIdentifier = false
module.exports = {
  getPartialIdentifier () {
    if (!partialIdentifier) {
      partialIdentifier = {
        UNI_COMPILER_VERSION: require('../package.json').version
      }
      Object.keys(process.env).forEach(name => {
        if (name.indexOf('UNI_') === 0) {
          partialIdentifier[name] = process.env[name]
        }
      })
    }
    return partialIdentifier
  },
  getAutomatorCode () {
    const automator = `@dcloudio/uni-${process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM}/dist/automator`
    return process.env.UNI_AUTOMATOR_WS_ENDPOINT ? `import '${automator}';` : ''
  },
  getWatchOptions () {
    return {
      ignored: [
        pathToGlob(path.resolve(process.env.UNI_INPUT_DIR), '*.md'),
        path.resolve(process.env.UNI_INPUT_DIR, '.hbuilderx'),
        path.resolve(process.env.UNI_INPUT_DIR, '.editorconfig'),
        path.resolve(process.env.UNI_INPUT_DIR, '.gitignore'),
        path.resolve(process.env.UNI_INPUT_DIR, 'LICENSE'),
        path.resolve(process.env.UNI_INPUT_DIR, 'unpackage'),
        path.resolve(process.env.UNI_INPUT_DIR, 'uniCloud-aliyun'),
        path.resolve(process.env.UNI_INPUT_DIR, 'uniCloud-tcb'),
        path.resolve(process.env.UNI_INPUT_DIR, 'uniCloud-alipay'),
        path.resolve(process.env.UNI_INPUT_DIR, 'uniCloud-dcloud'),
        path.resolve(process.env.UNI_INPUT_DIR, 'cloudfunctions-aliyun'),
        path.resolve(process.env.UNI_INPUT_DIR, 'cloudfunctions-tcb')
      ]
    }
  },
  getTsLoadOptions () {
    const {
      isInHBuilderX // 在 HBuilderX 的插件中
    } = require('@dcloudio/uni-cli-shared')
    const userTsConfigJson = path.resolve(process.env.UNI_INPUT_DIR, 'tsconfig.json')
    const defaultTsConfigJson = path.resolve(process.env.UNI_CLI_CONTEXT, 'tsconfig.json')
 
    const tsConfigJsonFile = fs.existsSync(userTsConfigJson) ? userTsConfigJson : defaultTsConfigJson
 
    const context = isInHBuilderX ? process.env.UNI_INPUT_DIR : process.env.UNI_CLI_CONTEXT
 
    function resolveModule (dir) {
      return path.resolve(process.env.UNI_CLI_CONTEXT, './node_modules', dir)
    }
 
    return {
      context,
      configFile: tsConfigJsonFile,
      compilerOptions: {
        baseUrl: context,
        typeRoots: [
          resolveModule('@dcloudio/types'),
          resolveModule('@types'),
          path.resolve(process.env.UNI_CLI_CONTEXT, 'types')
        ],
        types: [
          'uni-app',
          'uni-app-vue2',
          'webpack-env'
        ],
        paths: {
          '@/*': [
            path.join(process.env.UNI_INPUT_DIR, '*')
          ],
          vue: [
            resolveModule('vue')
          ],
          vuex: [
            resolveModule('vuex')
          ],
          'vue-class-component': [
            resolveModule('vue-class-component')
          ],
          'vue-property-decorator': [
            resolveModule('vue-property-decorator')
          ],
          tslib: [
            resolveModule('tslib')
          ],
          'mpvue-page-factory': [
            resolveModule('@dcloudio/vue-cli-plugin-uni/packages/mpvue-page-factory')
          ],
          '@vue/composition-api': [
            resolveModule('@dcloudio/vue-cli-plugin-uni/packages/@vue/composition-api')
          ],
          '@dcloudio/uni-app': [
            resolveModule('@dcloudio/uni-app')
          ]
        }
      },
      errorFormatter (error, colors) {
        const messageColor = error.severity === 'warning' ? colors.bold.yellow : colors.bold.red
        const filePath = path.relative(process.env.UNI_INPUT_DIR, error.file).replace('.vue.ts', '.vue')
        if (error.code === 2307 && error.content.includes('.vue')) {
          error.content = error.content.replace('Cannot find module ', '') +
            ' script 节点必须使用 lang="ts",文档参考地址:https://uniapp.dcloud.io/frame?id=vue-ts'
        }
        return messageColor(
          `[tsl] ERROR at ${filePath}:${error.line}
    TS${error.code}:${error.content}`
        )
      }
    }
  }
}