vue3-vant-mobile/vite.config.ts

106 lines
2.4 KiB
TypeScript
Raw Normal View History

import path from 'path'
2022-06-04 07:07:46 +00:00
import { loadEnv } from 'vite'
2022-06-16 13:51:46 +00:00
import type { ConfigEnv, UserConfig } from 'vite'
2022-08-16 02:57:15 +00:00
2022-06-16 13:51:46 +00:00
import { visualizer } from 'rollup-plugin-visualizer'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
2022-08-16 02:57:15 +00:00
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { viteVConsole } from 'vite-plugin-vconsole'
import mock from './build/mock/createMockServer'
2022-05-27 15:19:49 +00:00
export default ({ command, mode }: ConfigEnv): UserConfig => {
2022-06-04 07:07:46 +00:00
const root = process.cwd()
const env = loadEnv(mode, root)
2022-06-04 07:07:46 +00:00
return {
base: env.VITE_APP_PUBLIC_PATH,
2022-06-04 07:07:46 +00:00
define: {
'process.env.VUE_APP_API_BASE_URL': JSON.stringify(env.VITE_APP_API_BASE_URL),
'process.env.VUE_APP_PUBLIC_PATH': JSON.stringify(env.VITE_APP_PUBLIC_PATH)
2022-06-04 07:07:46 +00:00
},
2022-06-04 07:07:46 +00:00
plugins: [
vue(),
2022-06-16 13:51:46 +00:00
vueJsx(),
visualizer(),
legacy({
targets: ['defaults', 'not IE 11']
}),
Components({
dts: true,
resolvers: [VantResolver()],
types: []
}),
AutoImport({
include: [
/\.[tj]sx?$/,
/\.vue$/,
/\.vue\?vue/,
],
imports: [
'vue',
'vue-router',
2022-08-16 02:57:15 +00:00
'vitest'
],
dts: true,
eslintrc: {
enabled: true
}
}),
viteVConsole({
entry: [path.resolve('src/main.ts')],
localEnabled: command === 'serve',
enabled: false,
config: {
maxLogNumber: 1000,
theme: 'light'
}
}),
mock({
watch: true,
mockUrlList: [/api/],
cwd: process.cwd(),
enable: env.VITE_HTTP_MOCK && env.VITE_MOCK && process.env.NODE_ENV !== 'production',
})
2022-06-04 07:07:46 +00:00
],
2022-06-23 07:43:05 +00:00
build: {
cssCodeSplit: false,
chunkSizeWarningLimit: 2048
},
2022-06-04 07:07:46 +00:00
resolve: {
alias: {
'~@': path.join(__dirname, './src'),
'@': path.join(__dirname, './src'),
'~': path.join(__dirname, './src/assets')
}
2022-06-04 07:07:46 +00:00
},
2022-06-04 07:07:46 +00:00
server: {
host: true,
port: 3000,
proxy: env.VITE_HTTP_MOCK && env.VITE_MOCK && process.env.NODE_ENV !== 'production' ? undefined : {
2022-06-04 07:07:46 +00:00
'/api': {
// backend url
target: '',
2022-06-04 07:07:46 +00:00
ws: false,
changeOrigin: true,
}
}
2022-06-04 07:07:46 +00:00
}
}
}