https://vitejs.cn/vite3-cn/config/shared-options.html#base
vite.config.ts:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import { visualizer } from 'rollup-plugin-visualizer'
// https://vitejs.dev/config/
export default defineConfig({
base: 'doc',
server: {
port: 3007,
proxy: {
'/api': {
target: 'http://localhost:85',
changeOrigin: true,
rewrite: (path) => {
console.log(path)
return path.replace(/^\/api/, '/api')
},
}
}
},
plugins: [
vue(),
vueJsx(),
vueDevTools(),
visualizer(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
打印环境变量:
let env = import.meta.env
console.log('env', env)
页面路由:
router/index.ts:
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
redirect: '/home',
},
{
path: '/home',
component: () => import('../views/index/Home.vue'),
},
],
})
export default router
人工智能学习网站