57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
|
|
import path from 'node:path'
|
|||
|
|
import { fileURLToPath } from 'node:url'
|
|||
|
|
import { defineConfig } from 'vite'
|
|||
|
|
import Uni from '@dcloudio/vite-plugin-uni'
|
|||
|
|
import UniHelperManifest from '@uni-helper/vite-plugin-uni-manifest'
|
|||
|
|
import UniHelperPages from '@uni-helper/vite-plugin-uni-pages'
|
|||
|
|
import UniHelperLayouts from '@uni-helper/vite-plugin-uni-layouts'
|
|||
|
|
import UniHelperComponents from '@uni-helper/vite-plugin-uni-components'
|
|||
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|||
|
|
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
|
|||
|
|
import { readRuntimeConfig } from './src/config/runtimeConfig.node'
|
|||
|
|
|
|||
|
|
/** 与 vite.config 同目录为项目根 */
|
|||
|
|
const projectRoot = path.dirname(fileURLToPath(import.meta.url))
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 运行时配置:src/config/runtime.{development|production}.json
|
|||
|
|
* (小程序侧由 runtimeEnv.js 相对路径 import,不走 vite alias)
|
|||
|
|
*/
|
|||
|
|
export default async ({ mode }) => {
|
|||
|
|
const cfgMode = mode === 'production' ? 'production' : 'development'
|
|||
|
|
const rc = readRuntimeConfig(projectRoot, cfgMode)
|
|||
|
|
|
|||
|
|
const UnoCSS = (await import('unocss/vite')).default
|
|||
|
|
return defineConfig({
|
|||
|
|
root: projectRoot,
|
|||
|
|
plugins: [
|
|||
|
|
UniHelperManifest(),
|
|||
|
|
UniHelperPages({
|
|||
|
|
dts: 'src/uni-pages.d.ts',
|
|||
|
|
}),
|
|||
|
|
UniHelperLayouts(),
|
|||
|
|
UniHelperComponents({
|
|||
|
|
dts: 'src/components.d.ts',
|
|||
|
|
directoryAsNamespace: true,
|
|||
|
|
resolvers: [WotResolver()],
|
|||
|
|
}),
|
|||
|
|
Uni(),
|
|||
|
|
AutoImport({
|
|||
|
|
imports: ['vue', '@vueuse/core', 'uni-app'],
|
|||
|
|
dts: 'src/auto-imports.d.ts',
|
|||
|
|
dirs: ['src/composables', 'src/stores', 'src/utils'],
|
|||
|
|
vueTemplate: true,
|
|||
|
|
}),
|
|||
|
|
UnoCSS(),
|
|||
|
|
],
|
|||
|
|
server: {
|
|||
|
|
proxy: {
|
|||
|
|
[rc.apiPrefix]: {
|
|||
|
|
target: rc.apiUrl,
|
|||
|
|
changeOrigin: true,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
})
|
|||
|
|
}
|