Commit 448d808d by 胡悦

init

0 parents
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
{
"recommendations": ["Vue.volar"]
}
# Vue 3 + TypeScript + Vite
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
## Type Support For `.vue` Imports in TS
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
{
"name": "vite-ts-project",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^0.27.2",
"element-plus": "^2.2.8",
"js-sha1": "^0.6.0",
"md5": "^2.3.0",
"qs": "^6.11.0",
"vant": "^3.5.3",
"vue": "^3.2.25",
"vue-router": "^4.1.1",
"vuex": "^4.0.2"
},
"devDependencies": {
"@types/node": "^18.0.3",
"@types/qs": "^6.9.7",
"@vitejs/plugin-vue": "^2.3.3",
"sass": "^1.53.0",
"sass-loader": "^13.0.2",
"typescript": "^4.5.4",
"vite": "^2.9.9",
"vite-plugin-style-import": "^1.4.1",
"vue-tsc": "^0.34.7"
}
}
No preview for this file type
<template>
<div>
<router-view />
</div>
</template>
<script lang="ts" setup>
</script>
<style>
.flex-grow {
flex-grow: 1;
}
</style>
//
const modulesFiles = import.meta.globEager('./modules/*.ts')
console.log(modulesFiles)
const modules: any = {}
for (const key in modulesFiles) {
if (Object.prototype.hasOwnProperty.call(modulesFiles, key)) {
modules[key.replace(/(\.\/modules\/|\.ts)/g, '')] = modulesFiles[key].default
}
}
console.log(modules)
export default modules
\ No newline at end of file
import request from "../../utils/request";
const getList = ( data: Object ) => {
return request({
url: "/classify/getList",
method: "get",
data
})
}
export default {
getList
}
\ No newline at end of file
<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg">
<path
d="M127.88 73.143c0 1.412-.506 2.635-1.518 3.669-1.011 1.033-2.209 1.55-3.592 1.55h-17.887c0 9.296-1.783 17.178-5.35 23.645l16.609 17.044c1.011 1.034 1.517 2.257 1.517 3.67 0 1.412-.506 2.635-1.517 3.668-.958 1.033-2.155 1.55-3.593 1.55-1.438 0-2.635-.517-3.593-1.55l-15.811-16.063a15.49 15.49 0 0 1-1.196 1.06c-.532.434-1.65 1.208-3.353 2.322a50.104 50.104 0 0 1-5.192 2.974c-1.758.87-3.94 1.658-6.546 2.364-2.607.706-5.189 1.06-7.748 1.06V47.044H58.89v73.062c-2.716 0-5.417-.367-8.106-1.102-2.688-.734-5.003-1.631-6.945-2.692a66.769 66.769 0 0 1-5.268-3.179c-1.571-1.057-2.73-1.94-3.476-2.65L33.9 109.34l-14.611 16.877c-1.066 1.14-2.344 1.711-3.833 1.711-1.277 0-2.422-.434-3.434-1.304-1.012-.978-1.557-2.187-1.635-3.627-.079-1.44.333-2.705 1.236-3.794l16.129-18.51c-3.087-6.197-4.63-13.644-4.63-22.342H5.235c-1.383 0-2.58-.517-3.592-1.55S.125 74.545.125 73.132c0-1.412.506-2.635 1.518-3.668 1.012-1.034 2.21-1.55 3.592-1.55h17.887V43.939L9.308 29.833c-1.012-1.033-1.517-2.256-1.517-3.669 0-1.412.505-2.635 1.517-3.668 1.012-1.034 2.21-1.55 3.593-1.55s2.58.516 3.593 1.55l13.813 14.106h67.396l13.814-14.106c1.012-1.034 2.21-1.55 3.592-1.55 1.384 0 2.581.516 3.593 1.55 1.012 1.033 1.518 2.256 1.518 3.668 0 1.413-.506 2.636-1.518 3.67l-13.814 14.105v23.975h17.887c1.383 0 2.58.516 3.593 1.55 1.011 1.033 1.517 2.256 1.517 3.668l-.005.01zM89.552 26.175H38.448c0-7.23 2.489-13.386 7.466-18.469C50.892 2.623 56.92.082 64 .082c7.08 0 13.108 2.541 18.086 7.624 4.977 5.083 7.466 11.24 7.466 18.469z"
/>
</svg>
\ No newline at end of file
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<template>
<div>
<h1>{{ msg }}</h1>
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VS Code</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
</p>
<p>See <code>README.md</code> for more information.</p>
<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Docs
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
</p>
<button type="button" @click="count++">count is: {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
<svg-icon iconClass="bug"></svg-icon>
</div>
</template>
<template>
<svg :class="svgClass" aria-hidden="true" v-on="$attrs">
<use :xlink:href="iconName" />
</svg>
</template>
<script lang="ts">
import { defineComponent, computed } from 'vue'
interface Props {
iconClass: string
className: string
}
export default defineComponent({
name: 'SvgIcon',
props: {
iconClass: {
type: String,
required: true
},
className: {
type: String,
default: () => ''
}
},
setup(props: Props) {
const iconName = computed((): string => `#icon-${props.iconClass}`)
const svgClass = computed((): string => {
if (props.className) {
return 'svg-icon ' + props.className
} else {
return 'svg-icon'
}
})
console.log(props)
return {
iconName,
svgClass
}
}
})
</script>
<style scoped>
.svg-icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
</style>
File mode changed
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
}
import type {App} from 'vue'
import {
ElMessage,
ElButton,
ElMenu,
ElSubMenu,
ElMenuItem,
ElImage,
ElCard
} from 'element-plus'
// import locale from 'element-plus/lib/locale'
// import lang from 'element-plus/lib/locale/lang/zh-cn'
// locale.use(lang)
const components = [ElButton, ElMenu, ElSubMenu, ElMenuItem, ElImage, ElCard]
const plugins = [ElMessage]
export function setupElement(app: App<Element>): void {
components.forEach((component:any) => {
app.component(component.name, component)
})
plugins.forEach((plugin: any) => {
app.use(plugin)
})
app.config.globalProperties.$ELEMENT = {size: 'small', zindex: 3000}
}
\ No newline at end of file
import {
}
\ No newline at end of file
import { createApp } from 'vue'
import { setupStore } from './store'
import apis from './api/index'
import router, { setupRouter } from './router'
import App from './App.vue'
import SvgIcon from 'comps/SvgIcon/index.vue'
import { Button } from 'vant'
// import "vant/lib/index.css"
import 'assets/styles/common.scss'
const app = createApp(App)
app.use(Button)
app.component('svg-icon', SvgIcon)
console.log()
console.log(apis)
app.config.globalProperties.$axios = apis
setupStore(app)
setupRouter(app)
const fetchConfig = function (isEnv = true) {
return window.fetch('https://oss-config.dev.glsx.com.cn/mock/618cb9331072f92988f05a23/wx/config', {}).then(res => res.json())
}
app.config.globalProperties.$mockConfig = await fetchConfig()
router.isReady().then(() => {
app.mount('#app')
})
// createApp(App).component('svg-icon', SvgIcon).mount('#app')
import { readFileSync, readdirSync } from 'fs'
let idPerfix = ''
const svgTitle = /<svg([^>+].*?)>/
const clearHeightWidth = /(width|height)="([^>+].*?)"/g
const hasViewBox = /(viewBox="[^>+].*?")/g
const clearReturn = /(\r)|(\n)/g
function findSvgFile(dir) {
const svgRes = []
const dirents = readdirSync(dir, {
withFileTypes: true
})
for (const dirent of dirents) {
if (dirent.isDirectory()) {
svgRes.push(...findSvgFile(dir + dirent.name + '/'))
} else {
const svg = readFileSync(dir + dirent.name)
.toString()
.replace(clearReturn, '')
.replace(svgTitle, ($1, $2) => {
// console.log(++i)
// console.log(dirent.name)
let width = 0
let height = 0
let content = $2.replace(clearHeightWidth, (s1, s2, s3) => {
if (s2 === 'width') {
width = s3
} else if (s2 === 'height') {
height = s3
}
return ''
})
if (!hasViewBox.test($2)) {
content += `viewBox="0 0 ${width} ${height}"`
}
return `<symbol id="${idPerfix}-${dirent.name.replace('.svg', '')}" ${content}>`
})
.replace('</svg>', '</symbol>')
svgRes.push(svg)
}
}
return svgRes
}
export const svgBuilder = (path, perfix = 'icon') => {
if (path === '') return
idPerfix = perfix
const res = findSvgFile(path)
// console.log(res.length)
// const res = []
return {
name: 'svg-transform',
transformIndexHtml(html) {
return html.replace(
'<body>',
`
<body>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position: absolute; width: 0; height: 0">
${res.join('')}
</svg>
`
)
}
}
}
import { createRouter, createWebHistory } from 'vue-router'
import type { App } from 'vue'
import routes from './routes'
const routerHistory = createWebHistory()
// createWebHashHistory hash 路由
// createWebHistory history 路由
// createMemoryHistory 带缓存history路由
console.log(routes)
const router = createRouter({
history: routerHistory,
routes: routes
})
// 删除/重置路由
export function resetRoute():void {
router.getRoutes().forEach(route => {
const {name} = route
if (name) {
router.hasRoute(name) && router.removeRoute(name)
}
})
}
export function setupRouter(app: App<Element>) {
app.use(router)
}
export default router
\ No newline at end of file
import HelloWorld from 'comps/HelloWorld.vue'
const staticRoutes = Object.freeze([
{
path: '/',
component: () => import('views/home/index.vue')
},
{
name: 'Home',
path: '/home',
component: () => import('views/home/index.vue')
},
{
name: 'Login',
path: '/login',
component: () => import('views/login/index.vue')
},
{
name: 'Project',
path: '/project',
component: () => import('views/project/index.vue')
}
])
export default staticRoutes
import { InjectionKey } from "vue";
import {createStore, useStore as baseUseStore, Store} from 'vuex'
import type {App} from 'vue'
export interface State {
count: number
}
// 定义注入类型
const key :InjectionKey<State> = Symbol()
const store = createStore<State>({
state() {
return {
count: 0
}
},
mutations: {
increment(state: State) {
state.count++
}
}
})
// 将类型注入useStore,似乎无效
export function useStore() {
return baseUseStore(key)
}
export function setupStore(app: App<Element>) {
app.use(store, key)
}
export default store
\ No newline at end of file
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'
import { ElMessage, ElMessageBox } from 'element-plus'
import router, { resetRoute } from '../router'
import qs from 'qs'
import { createSign } from './util'
function getSession(key: string) {
let json: any = window.sessionStorage.getItem(key)
return JSON.parse(json)
}
export const PATH_URL: string = '/api' || import.meta.env.VITE_API_URL
// 配置新建一个axios 实例
const service: AxiosInstance = axios.create({
baseURL: PATH_URL,
timeout: 50000,
headers: {
'Content-Type': 'application/json'
}
})
const customer = {
response: '1',
alert: '2',
sign: {
a: '10',
b: '11'
},
secret: '4',
signWay: '5',
// sessionId: headers.token
}
// 添加请求拦截器
service.interceptors.request.use(
(config: AxiosRequestConfig) => {
console.log(config)
let { data = {}, sign = true, noSignAttr = []} = config
if (sign) {
let _configSign = customer.sign || {}
data = createSign(Object.assign({}, _configSign, data), customer.secret, noSignAttr, customer.signWay)
}
const method = config.method?.toLowerCase()
if (method == 'get') {
config.params = data
} else if (method == 'post') {
config.data = qs.stringify(data)
}
// if (getSession('token')) {
// config.headers.common['Authorization'] = `${getSession('token')}`
// }
return config
},
(error:AxiosError) => {
return Promise.reject(error)
}
)
// 添加响应拦截器
service.interceptors.response.use(
(response: AxiosResponse) => {
const res = response.data
if (res.code&& res.code!==0) {
if (res.code === 401 || res.code == 4001){
window.sessionStorage.clear()
router.push('/login')
resetRoute()
ElMessageBox.alert('请重新登录', '提示', {}).then(() => {}).catch(() => {})
}
return Promise.reject(service.interceptors.response)
} else {
return response.data
}
},
(error:AxiosError) => {
if (error.message.indexOf('timeout') != -1) {
ElMessage.error('网络超时')
} else if (error.message == 'Network Error') {
ElMessage.error('网络连接错误')
} else {
ElMessage.error(error.message)
}
return Promise.reject(error)
}
)
export default service
\ No newline at end of file
const hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
// const b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
const chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
// let binb2hex;
// function b64_sha1(s: string): string { return binb2b64(coreSha1(str2binb(s), s.length * chrsz)); }
// function str_sha1(s: string): string { return binb2str(coreSha1(str2binb(s), s.length * chrsz)); }
// function hex_hmac_sha1(key: string, data: string): string { return binb2hex(core_hmac_sha1(key, data)); }
// function b64_hmac_sha1(key: string, data: string): string { return binb2b64(core_hmac_sha1(key, data)); }
// function str_hmac_sha1(key: string, data: string): string { return binb2str(core_hmac_sha1(key, data)); }
/*
* Perform a simple self-test to see if the VM is working
*/
// function sha1_vm_test(): boolean {
// return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
// }
/*
* Calculate the SHA-1 of an array of big-endian words, and a bit length
*/
function rol(num: number, cnt: number): number {
return (num << cnt) | (num >>> (32 - cnt));
}
function safeAdd(x: number, y: number): number {
const lsw = (x & 0xFFFF) + (y & 0xFFFF);
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function sha1Ft(t: number, b: number, c: number, d: number): number {
if (t < 20) return (b & c) | ((~b) & d);
if (t < 40) return b ^ c ^ d;
if (t < 60) return (b & c) | (b & d) | (c & d);
return b ^ c ^ d;
}
/*
* Determine the appropriate additive constant for the current iteration
*/
function sha1Kt(t: number): number {
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
(t < 60) ? -1894007588 : -899497514;
}
function coreSha1(x: number[], len: number): number[] {
/* append padding */
x[len >> 5] |= 0x80 << (24 - len % 32);
x[((len + 64 >> 9) << 4) + 15] = len;
const w = Array(80);
let a = 1732584193;
let b = -271733879;
let c = -1732584194;
let d = 271733878;
let e = -1009589776;
for (let i = 0; i < x.length; i += 16) {
const olda = a;
const oldb = b;
const oldc = c;
const oldd = d;
const olde = e;
for (let j = 0; j < 80; j++) {
if (j < 16) w[j] = x[i + j];
else w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
const t = safeAdd(safeAdd(rol(a, 5), sha1Ft(j, b, c, d)),
safeAdd(safeAdd(e, w[j]), sha1Kt(j)));
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
}
a = safeAdd(a, olda);
b = safeAdd(b, oldb);
c = safeAdd(c, oldc);
d = safeAdd(d, oldd);
e = safeAdd(e, olde);
}
return [a, b, c, d, e];
}
/*
* Perform the appropriate tripconst combination function for the current
* iteration
*/
/*
* Calculate the HMAC-SHA1 of a key and some data
*/
// function core_hmac_sha1(key: string, data: string): number[] {
// let bkey = str2binb(key);
// if (bkey.length > 16) bkey = coreSha1(bkey, key.length * chrsz);
// const ipad = Array(16), opad = Array(16);
// for (const i = 0; i < 16; i++) {
// ipad[i] = bkey[i] ^ 0x36363636;
// opad[i] = bkey[i] ^ 0x5C5C5C5C;
// }
// const hash = coreSha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
// return coreSha1(opad.concat(hash), 512 + 160);
// }
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
/*
* Bitwise rotate a 32-bit number to the left.
*/
/*
* Convert an 8-bit or 16-bit string to an array of big-endian words
* In 8-bit function, characters >255 have their hi-byte silently ignored.
*/
function str2binb(str: string): number[] {
const bin: number[] = [];
const mask = (1 << chrsz) - 1;
for (let i = 0; i < str.length * chrsz; i += chrsz)
bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i % 32);
return bin;
}
/*
* Convert an array of big-endian words to a string
*/
// function binb2str(bin: number[]): string {
// const str = "";
// const mask = (1 << chrsz) - 1;
// for (const i = 0; i < bin.length * 32; i += chrsz)
// str += String.fromCharCode((bin[i >> 5] >>> (32 - chrsz - i % 32)) & mask);
// return str;
// }
/*
* Convert an array of big-endian words to a hex string.
*/
function binb2hex(binarray: number[]): string {
const hexTab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
let str = "";
for (let i = 0; i < binarray.length * 4; i++) {
str += hexTab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) +
hexTab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
}
return str;
}
/*
* Convert an array of big-endian words to a base-64 string
*/
// function binb2b64(binarray: number[]): string {
// const tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
// const str = "";
// for (const i = 0; i < binarray.length * 4; i += 3) {
// const tripconst = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16)
// | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8)
// | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
// for (const j = 0; j < 4; j++) {
// if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
// else str += tab.charAt((tripconst >> 6 * (3 - j)) & 0x3F);
// }
// }
// return str;
// }
export function hexSha1(s: string): string { return binb2hex(coreSha1(str2binb(s), s.length * chrsz)).toUpperCase(); }
export function hexSha2(s: string): string { return binb2hex(coreSha1(str2binb(s), s.length * chrsz)); }
// 字符串加密成 hex 字符串
import { hexSha2 } from './sha1'
import qs from 'qs'
export const Util = {
createSign: function(params: Object, secret: String, noSignAttr = [], way = 'hexSha2') {
delete params.sign
params.timestamp = new Date().getTime()
console.log(params)
var strQs = qs.stringify(params, { arrayFormat: 'indices', allowDots: true, encodeValuesOnly: true })
const objQs = strQs.split('&')
const collect = objQs.reduce((collect, item) => {
const [key, value] = item.split('=')
if (value === null) {
value = ''
} else if (typeof value === 'object') {
value = JSON.stringify(value)
}
collect[key] = decodeURIComponent(value)
return collect
}, {})
const keys = Object.keys(collect).sort()
const str = keys.reduce((col, key) => {
if (!noSignAttr.includes(key)) {
col.push(key, collect[key])
}
return col
}, [])
collect.sign = hexSha2(secret + str.join('') + secret).toUpperCase()
return collect
}
}
export const createSign = Util.createSign
export default Util
\ No newline at end of file
<template>
<div>
<van-button type="primary" @click="getList">调用接口</van-button>
<van-button type="primary" @click="toLogin">跳转1</van-button>
<van-button type="success" @click="toJump">跳转2</van-button>
</div>
</template>
<script lang="ts" setup>
import { useRouter } from 'vue-router';
import { getCurrentInstance } from 'vue';
const router = useRouter()
const {proxy}: any = getCurrentInstance()
const getList = async() => {
console.log(proxy.$axios)
let res = await proxy.$axios.classify.getList({id: 0})
console.log(res)
}
// getList()
const toLogin = () => {
router.push('/login')
}
const toJump = () => {
router.push('/project')
}
// toLogin()
</script>
<template>
<div>
这里是登录
</div>
</template>
<script lang="ts" setup>
</script>
<template>
<div>
这里是第二个页面
</div>
</template>
<script lang="ts" setup>
</script>
{
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"skipLibCheck": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
},
"include": ["vite.config.ts"]
}
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import styleImport, { VantResolve } from 'vite-plugin-style-import';
import path from 'path'
import { svgBuilder } from './src/plugins/svgBuilder'
const resolve = (dir: string) => path.join(__dirname, dir)
// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [
vue(),
[svgBuilder('./src/assets/icons/svg/')], // 这里已经将src/icons/svg/下的svg全部导入,无需再单独导入
styleImport({
resolves: [VantResolve()],
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: (name) => {
return `../es/${name}/style`
}
}
]
})
],
resolve: {
alias: {
'@': resolve('src'),
comps: resolve('src/components'),
apis: resolve('src/apis'),
views: resolve('src/views'),
routes: resolve('src/routes'),
assets: resolve('src/assets')
}
},
server: {
// 服务器主机名
host: '0.0.0.0',
// 端口号
port: 3000,
// 设为true时 端口已被占用则会直接退出,而不是尝试下一个可用端口
strictPort: false,
// 服务器启动时自动在浏览器中打开应用程序,当此值为字符串时,会被用作URL的路径名
open: false,
// 自定义代理规则
proxy: {
'/api': {
target: 'http://192.168.1.68:7001',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
}
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!