| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import { defineConfig, loadEnv } from 'vite';
- import path from 'path';
- import Components from '@uni-helper/vite-plugin-uni-components';
- import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers';
- import uni from '@dcloudio/vite-plugin-uni';
- export default defineConfig(({ mode }) => {
- const env = loadEnv(mode, path.join(process.cwd(), 'env'));
- return {
- envDir: './env',// 环境目录
- css: {
- preprocessorOptions: {
- scss: {// 全局导入
- charset: false,
- additionalData: '@import "@/uni.scss";',
- }
- }
- },
- resolve: {
- // 别名
- alias: [
- {
- find: '@',
- replacement: path.resolve(__dirname, 'src'),
- }
- ],
- // 忽略文件后缀名
- extensions: ['.js', '.ts', '.vue', '.scss', '.json']
- },
- server: {
- // 监听所有地址
- host: '0.0.0.0',
- // 端口号
- port: 3000,
- // 自动打开浏览器
- open: true,
- // 热更新
- hmr: true,
- // 自动更换可用端口
- strictPort: false,
- // 代理规则
- proxy: {
- '/api': {
- // 开启跨域
- changeOrigin: true,
- // 转发地址
- target: env.VITE_API_URL,
- // 路径重写
- rewrite: (path) => path.replace(/^\/api/, ''),
- },
- }
- },
- build: {
- chunkSizeWarningLimit: 2048,// chunk大于2M触发警告
- },
- esbuild: {
- drop: mode === 'production' ? ['console', 'debugger'] : [],
- },
- plugins: [
- Components({// 自动导入组件
- resolvers: [WotResolver()],
- dts: 'src/typings/components.d.ts'
- }),
- [uni()],// Uni-App编译
- ],
- }
- })
|