h_cg 6c6c3e71c5 build(dependencies): 更新依赖版本并调整样式语言
- 更新 @dcloudio/uni-* 包版本至 3.0.0-alpha-4030220241101001
- 移除 @rollup/plugin-node-resolve 依赖- 将 App.vue 中的样式语言从 scss 改为 css
2024-11-09 16:49:09 +08:00

58 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { PluginOption } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
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(),
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,
}),
];
}