| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { defineConfig } from "vite";
- import vue from "@vitejs/plugin-vue";
- import path from "path";
- import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
- const resolve = (dir) => path.join(__dirname, dir);
- // 获取时间戳
- const version = new Date().getTime();
- // https://vitejs.dev/config/
- export default defineConfig({
- plugins: [
- vue(),
- createSvgIconsPlugin({
- // 指定 SVG 图标目录(绝对路径)
- iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
- // 指定 symbolId 格式
- symbolId: "icon-[dir]-[name]",
- // 自定义插入位置(可选)
- inject: "body-last",
- }),
- ],
- resolve: {
- alias: {
- "@": resolve("src"),
- },
- },
- base: "/", // History 模式下必须用绝对路径,避免深层路由把 JS 解析成相对 assets 路径
- // 反向代理
- server: {
- port: 8050,
- host: "0.0.0.0",
- open: false, // 服务启动时是否自动打开浏览器true
- hmr: true, // 开启热更新
- cors: true, // 允许跨域
- proxy: {
- "/dev-api": {
- changeOrigin: true, //是否允许跨域
- target: "https://prpms.eiacloud.com/", // 本地测试地址
- rewrite: (path) => path.replace(/^\/dev-api/, ""),
- },
- },
- },
- css: {
- preprocessorOptions: {
- less: {
- additionalData: `@import "${path.resolve(
- __dirname,
- "src/assets/styles/commonStyle.less"
- )}";`,
- },
- },
- },
- build: {
- // 配置输出文件名
- rollupOptions: {
- output: {
- // JS 文件添加时间戳
- entryFileNames: `assets/js/[name].${version}.js`,
- chunkFileNames: `assets/js/[name].${version}.js`,
- assetFileNames: `assets/css/[name].${version}.[ext]`, // CSS 文件添加时间戳
- },
- },
- },
- });
|