12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import { fileURLToPath, URL } from 'node:url'
- import { defineConfig, loadEnv } from 'vite'
- import Unocss from 'unocss/vite'
- import vue from '@vitejs/plugin-vue'
- import vueJsx from '@vitejs/plugin-vue-jsx'
- import VueDevTools from 'vite-plugin-vue-devtools'
- import vueSetupExtend from 'vite-plugin-vue-setup-extend'
- import viteCompression from 'vite-plugin-compression'
- import AutoImport from 'unplugin-auto-import/vite'
- import Components from 'unplugin-vue-components/vite'
- import { VantResolver } from 'unplugin-vue-components/resolvers'
- import { resolve } from 'path'
- import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
- const env = process.env.NODE_ENV;
- export default defineConfig({
- plugins: [
- vue(),
- Unocss(),
- vueJsx(),
- VueDevTools(),
- vueSetupExtend(),
- Components({
- extensions: ['vue', 'tsx', 'md'],
- globs: ['src/components/*/*.vue', 'src/components/*/*.tsx'],
- include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.[tj]sx?$/],
- resolvers: [VantResolver()],
- dts: 'src/typings/components.d.ts'
- }),
- AutoImport({
- include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
- imports: ['vue', 'vue-router'],
- dts: 'src/typings/auto-imports.d.ts',
- resolvers: [VantResolver()],
- eslintrc: {
- enabled: true,
- filepath: './.eslintrc-auto-import.json'
- }
- }),
- viteCompression({
- algorithm: 'gzip',
- ext: '.gz',
- deleteOriginFile: false,
- threshold: 1024
- }),
- viteCompression({
- algorithm: 'brotliCompress',
- ext: '.br',
- deleteOriginFile: false,
- threshold: 1024
- }),
- // svg 图标
- createSvgIconsPlugin({
- iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
- svgoOptions: true,
- symbolId: 'icon-[dir]-[name]'
- })
- ],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url))
- }
- },
- base:env === 'production' ? '/mobile' : '/',
- server: {
- host: '0.0.0.0',
- port: 3200,
- open: true,
- proxy: {
- '/api': {
- target: 'http://localhost:3000',
- // target: 'https://demo.lowflow.vip/api',
- changeOrigin: true,
- ws: true,
- rewrite: (path) => path.replace(/^\/api/, ''),
- secure: false
- }
- }
- },
- build: {
- rollupOptions: {
- output: {
- // 打包分类
- chunkFileNames: 'assets/js/[name]-[hash].js',
- entryFileNames: 'assets/js/[name]-[hash].js',
- assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
- // 分包策略
- manualChunks: {
- vue: ['vue'],
- 'vue-router': ['vue-router']
- }
- }
- }
- }
- })
|