index.ts 1.2 KB
Newer Older
1
import path from 'path'
fxy060608's avatar
fxy060608 已提交
2

3
import { Plugin, ViteDevServer } from 'vite'
fxy060608's avatar
fxy060608 已提交
4

fxy060608's avatar
fxy060608 已提交
5
import { initEnv } from './env'
6 7 8 9 10
import { createLoad } from './load'
import { createConfig } from './config'
import { createResolveId } from './resolveId'
import { createConfigResolved } from './configResolved'
import { createConfigureServer } from './configureServer'
fxy060608's avatar
fxy060608 已提交
11

12 13 14
const { vueCompilerOptions } = require('@dcloudio/uni-cli-shared')
export interface VitePluginUniOptions {
  inputDir?: string
fxy060608's avatar
fxy060608 已提交
15
}
16 17 18 19
export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
  root: string
  inputDir: string
  devServer?: ViteDevServer
fxy060608's avatar
fxy060608 已提交
20
}
21 22 23 24 25 26 27 28 29 30 31

export const uniVueCompilerOptions = vueCompilerOptions

export default function uniPlugin(
  rawOptions: VitePluginUniOptions = {}
): Plugin {
  const options: VitePluginUniResolvedOptions = {
    ...rawOptions,
    root: process.cwd(),
    inputDir: rawOptions.inputDir || path.resolve(process.cwd(), 'src'),
  }
fxy060608's avatar
fxy060608 已提交
32
  initEnv(options)
33 34
  return {
    name: 'vite:uni',
35 36 37 38 39
    config: createConfig(options),
    configResolved: createConfigResolved(options),
    configureServer: createConfigureServer(options),
    resolveId: createResolveId(options),
    load: createLoad(options),
40 41
  }
}