index.ts 615 字节
Newer Older
1 2
import debug from 'debug'
import { Plugin } from 'vite'
fxy060608's avatar
fxy060608 已提交
3
import { VitePluginUniResolvedOptions } from '..'
4 5 6 7 8 9

const debugResolve = debug('uni:resolve')

const VUES = ['vue', 'vue.js', './vue.js', 'dist/vue.runtime.esm-bundler.js']

export function createResolveId(
fxy060608's avatar
fxy060608 已提交
10
  _options: VitePluginUniResolvedOptions
11 12
): Plugin['resolveId'] {
  return function (id) {
fxy060608's avatar
fxy060608 已提交
13 14 15 16 17
    if (id.startsWith('@dcloudio/') || id.startsWith('@vue/')) {
      return require.resolve(id, {
        paths: [process.env.UNI_CLI_CONTEXT!],
      })
    }
18 19 20 21 22 23
    if (VUES.includes(id)) {
      debugResolve(id)
      return '@dcloudio/uni-h5-vue'
    }
  }
}