xiongzhu 3 лет назад
Родитель
Сommit
af3a4c40c8
3 измененных файлов с 50 добавлено и 47 удалено
  1. 2 1
      .eslintrc.cjs
  2. 1 1
      src/router/index.js
  3. 47 45
      vite.config.js

+ 2 - 1
.eslintrc.cjs

@@ -12,6 +12,7 @@ module.exports = {
         'no-unused-vars': 'off'
     },
     globals: {
-        wx: true
+        wx: true,
+        process: true
     }
 }

+ 1 - 1
src/router/index.js

@@ -3,7 +3,7 @@ import TabsPage from '../views/TabsPage.vue'
 import { Page } from './Page'
 import { useUserStore } from '../stores/user'
 import { showConfirmDialog } from 'vant'
-
+console.log(import.meta.env.BASE_URL)
 const router = createRouter({
     history: createWebHistory(import.meta.env.BASE_URL),
     routes: [

+ 47 - 45
vite.config.js

@@ -1,53 +1,55 @@
 import { fileURLToPath, URL } from 'node:url'
-
-import { defineConfig } from 'vite'
+import { defineConfig, loadEnv } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import viteImagemin from 'vite-plugin-imagemin'
 
 // https://vitejs.dev/config/
-export default defineConfig({
-    server: {
-        host: '0.0.0.0'
-    },
-    plugins: [
-        vue(),
-        viteImagemin({
-            gifsicle: {
-                optimizationLevel: 7,
-                interlaced: false
-            },
-            optipng: false,
-            mozjpeg: {
-                quality: 20
-            },
-            pngquant: {
-                quality: [0.5, 0.9],
-                speed: 1
-            },
-            svgo: {
-                plugins: [
-                    {
-                        name: 'removeViewBox'
-                    },
-                    {
-                        name: 'removeEmptyAttrs',
-                        active: false
-                    }
-                ]
-            },
-            webp: false
-        })
-    ],
-    resolve: {
-        alias: {
-            '@': fileURLToPath(new URL('./src', import.meta.url))
-        }
-    },
-    css: {
-        preprocessorOptions: {
-            less: {
-                javascriptEnabled: true,
-                additionalData: '@import "@/styles/common.less";'
+export default defineConfig(({ command, mode }) => {
+    return {
+        base: mode === 'production' ? '/h5/' : '/',
+        server: {
+            host: '0.0.0.0'
+        },
+        plugins: [
+            vue(),
+            viteImagemin({
+                gifsicle: {
+                    optimizationLevel: 7,
+                    interlaced: false
+                },
+                optipng: false,
+                mozjpeg: {
+                    quality: 20
+                },
+                pngquant: {
+                    quality: [0.5, 0.9],
+                    speed: 1
+                },
+                svgo: {
+                    plugins: [
+                        {
+                            name: 'removeViewBox'
+                        },
+                        {
+                            name: 'removeEmptyAttrs',
+                            active: false
+                        }
+                    ]
+                },
+                webp: false
+            })
+        ],
+        resolve: {
+            alias: {
+                '@': fileURLToPath(new URL('./src', import.meta.url))
+            }
+        },
+        css: {
+            preprocessorOptions: {
+                less: {
+                    javascriptEnabled: true,
+                    additionalData: '@import "@/styles/common.less";'
+                }
             }
         }
     }