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

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

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

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

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'),
  }
31 32
  return {
    name: 'vite:uni',
33 34 35 36 37
    config: createConfig(options),
    configResolved: createConfigResolved(options),
    configureServer: createConfigureServer(options),
    resolveId: createResolveId(options),
    load: createLoad(options),
38 39
  }
}