zhxy-jsd/vite.config.ts
2026-01-10 10:09:15 +08:00

83 lines
2.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {defineConfig} from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import {resolve} from 'path'
import autdPlugin from './plugin/vite-plugin-autd'
import AutoImport from 'unplugin-auto-import/vite'
import AutoStylePlugin from "./plugin/vite-plugin-autoStyle";
import {HOMEAGENT} from "./src/config";
export default defineConfig({
server: {
proxy: {
"/base": {
target: HOMEAGENT,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/base/, ""),
},
},
},
plugins: [
//c 为class 例如 class="wi-10"
//w 为样式style 例如 width:10rpx
//t 为值开头 例如 color:#000
//w 为值结尾 例如 width:10rpx
AutoStylePlugin([
{c: 'wi', s: 'width', t: '', w: 'rpx'},
{c: 'he', s: 'height', t: '', w: 'rpx'},
{c: 'cor', s: 'color', t: '#', w: ''},
{c: 'back', s: 'background', t: '#', w: ''},
{c: 'bor', s: 'border', t: '1px solid #', w: ''},
{c: 'gridCols', s: 'grid-template-columns', t: 'repeat(', w: ', minmax(0, 1fr))'},
{c: 'gridRows', s: 'grid-template-rows', t: 'repeat(', w: ', minmax(0, 1fr))'},
{c: 'gapY', s: 'grid-row-gap', t: '', w: 'rpx'},
{c: 'gapX', s: 'grid-column-gap', t: '', w: 'rpx'},
{c: 'colSpan', s: 'grid-column', t: 'span ', w: ''},
{c: 'rowSpan', s: 'grid-row', t: 'span ', w: ''},
]),
autdPlugin(),
uni({
vueOptions: {
template: {
compilerOptions: {
isCustomElement: tag => tag.startsWith("amap")
}
}
}
}),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/, /\.vue\?vue/ // .vue
],
imports: ['vue', 'pinia'],
dts: "src/auto-import.d.ts" // 生成在src路径下名为auto-import.d.ts的声明文件
}),
],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'#': resolve(__dirname, './types')
}
},
optimizeDeps: {
include: ['jweixin-js-sdk']
},
build: {
// 确保文件名包含hashVite默认已包含这里显式配置
rollupOptions: {
output: {
// 确保文件名包含hash文件名变化就代表新版本
entryFileNames: `assets/[name]-[hash].js`,
chunkFileNames: `assets/[name]-[hash].js`,
assetFileNames: `assets/[name]-[hash].[ext]`
}
},
// 生成manifest文件用于版本管理可选
manifest: true,
commonjsOptions: {
include: [/jweixin-js-sdk/, /node_modules/],
transformMixedEsModules: true
}
}
});