index.ts 1.3 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
fxy060608's avatar
fxy060608 已提交
2

fxy060608's avatar
fxy060608 已提交
3
import { initEnv } from './env'
4 5 6 7
import { createConfig } from './config'
import { createResolveId } from './resolveId'
import { createConfigResolved } from './configResolved'
import { createConfigureServer } from './configureServer'
fxy060608's avatar
fxy060608 已提交
8
import { createHandleHotUpdate } from './handleHotUpdate'
9 10
export interface VitePluginUniOptions {
  inputDir?: string
fxy060608's avatar
fxy060608 已提交
11
  outputDir?: string
fxy060608's avatar
fxy060608 已提交
12
}
13 14
export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
  root: string
fxy060608's avatar
fxy060608 已提交
15
  base: string
fxy060608's avatar
fxy060608 已提交
16
  command: ResolvedConfig['command']
fxy060608's avatar
fxy060608 已提交
17
  platform: UniApp.PLATFORM
18
  inputDir: string
fxy060608's avatar
fxy060608 已提交
19
  outputDir: string
fxy060608's avatar
fxy060608 已提交
20
  assetsDir: string
21
  devServer?: ViteDevServer
fxy060608's avatar
fxy060608 已提交
22
}
23

fxy060608's avatar
fxy060608 已提交
24
export * from './vue'
25 26 27 28 29 30 31

export default function uniPlugin(
  rawOptions: VitePluginUniOptions = {}
): Plugin {
  const options: VitePluginUniResolvedOptions = {
    ...rawOptions,
    root: process.cwd(),
fxy060608's avatar
fxy060608 已提交
32
    base: '/',
fxy060608's avatar
fxy060608 已提交
33
    assetsDir: 'assets',
fxy060608's avatar
fxy060608 已提交
34 35
    inputDir: '',
    outputDir: '',
fxy060608's avatar
fxy060608 已提交
36
    command: 'serve',
fxy060608's avatar
fxy060608 已提交
37
    platform: 'h5',
38
  }
fxy060608's avatar
fxy060608 已提交
39
  initEnv(options)
40 41
  return {
    name: 'vite:uni',
42 43 44 45
    config: createConfig(options),
    configResolved: createConfigResolved(options),
    configureServer: createConfigureServer(options),
    resolveId: createResolveId(options),
fxy060608's avatar
fxy060608 已提交
46
    handleHotUpdate: createHandleHotUpdate(options),
47 48
  }
}