mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 06:12:44 +08:00
- 更新多个依赖到最新版本,包括 uni-app、alova、pinia、tailwindcss 等 - 移除 postcss.config.ts 配置文件 - 调整 vite 配置和 tailwindcss 引入方式 - 更新 App.vue 和 main.ts 中的样式引入 - 优化 stores 中的 defineStore 使用方式 - 新增 src/styles/main.css 文件
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import type { PluginOption } from 'vite';
|
||
import uni from '@dcloudio/vite-plugin-uni';
|
||
import tailwindcss from '@tailwindcss/vite';
|
||
import { visualizer } from 'rollup-plugin-visualizer';
|
||
import autoImport from 'unplugin-auto-import/vite';
|
||
import viteRestart from 'vite-plugin-restart';
|
||
import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite';
|
||
import { isH5, WeappTailwindcssDisabled } 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(),
|
||
tailwindcss(),
|
||
uvtw({
|
||
rem2rpx: true,
|
||
disabled: WeappTailwindcssDisabled,
|
||
// 使用新的 ast-grep 来处理 js 资源,速度是 babel 的2倍左右
|
||
// 需要先安装 `@ast-grep/napi`
|
||
// jsAstTool: 'ast-grep'
|
||
}),
|
||
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,
|
||
}),
|
||
];
|
||
}
|