mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 06:12:44 +08:00
- Introduced a new unocss.config.ts file to define styling configurations. - Configured presets for Weapp and Icons, including custom transform rules. - Set up theme colors and font sizes for consistent styling across the application. - Added transformers for attributify and class handling.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import type { PluginOption } from 'vite';
|
||
import uni from '@dcloudio/vite-plugin-uni';
|
||
import { visualizer } from 'rollup-plugin-visualizer';
|
||
import Unocss from 'unocss/vite';
|
||
import autoImport from 'unplugin-auto-import/vite';
|
||
import viteRestart from 'vite-plugin-restart';
|
||
import { isH5 } from './platform';
|
||
|
||
interface VitePluginConfig {
|
||
isProd: boolean
|
||
}
|
||
|
||
export function createVitePlugins({ isProd }: VitePluginConfig): PluginOption[] {
|
||
return [
|
||
// @ts-expect-error TODO uni() 会报错:uni is not a function,暂时使用此方式解决
|
||
uni?.default(),
|
||
Unocss({
|
||
hmrTopLevelAwait: false,
|
||
}),
|
||
autoImport({
|
||
include: [
|
||
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
|
||
/\.vue$/,
|
||
/\.vue\?vue/, // .vue
|
||
],
|
||
imports: [
|
||
'vue',
|
||
'uni-app',
|
||
'pinia',
|
||
{
|
||
'uni-mini-router': ['useRouter', 'useRoute'],
|
||
},
|
||
{
|
||
'alova/client': ['useRequest'],
|
||
},
|
||
],
|
||
dts: 'typings/auto-imports.d.ts',
|
||
eslintrc: {
|
||
enabled: true,
|
||
},
|
||
}),
|
||
viteRestart({
|
||
restart: ['vite.config.ts', 'src/pages.json'],
|
||
}),
|
||
isH5 && isProd
|
||
&& visualizer({
|
||
filename: './node_modules/.cache/visualizer/stats.html',
|
||
open: true,
|
||
gzipSize: true,
|
||
brotliSize: true,
|
||
}),
|
||
];
|
||
}
|