116 lines
4.1 KiB
TypeScript
116 lines
4.1 KiB
TypeScript
|
import { ConfigEnv, defineConfig, loadEnv, UserConfigExport } from 'vite'
|
|||
|
import vue from '@vitejs/plugin-vue'
|
|||
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|||
|
import { resolve } from 'path'
|
|||
|
import viteCompression from 'vite-plugin-compression'
|
|||
|
import { ArcoResolver } from 'unplugin-vue-components/resolvers'
|
|||
|
import Components from 'unplugin-vue-components/vite'
|
|||
|
import AutoImport from 'unplugin-auto-import/vite'
|
|||
|
|
|||
|
const autoImport = AutoImport({
|
|||
|
imports: ['vue', 'vue-router', '@vueuse/core'],
|
|||
|
resolvers: [ArcoResolver()],
|
|||
|
eslintrc: {
|
|||
|
enabled: true
|
|||
|
}
|
|||
|
})
|
|||
|
// Ensure .d.ts file is created when running `vite optimize`
|
|||
|
autoImport.buildStart()
|
|||
|
|
|||
|
// https://vitejs.dev/config/
|
|||
|
export default async (config: ConfigEnv): Promise<UserConfigExport> => {
|
|||
|
return defineConfig({
|
|||
|
plugins: [
|
|||
|
vue(),
|
|||
|
vueJsx(),
|
|||
|
viteCompression(),
|
|||
|
autoImport,
|
|||
|
Components({
|
|||
|
resolvers: [
|
|||
|
ArcoResolver({
|
|||
|
sideEffect: false
|
|||
|
}),
|
|||
|
{
|
|||
|
type: 'component',
|
|||
|
resolve: (name: string) => {
|
|||
|
if (name === 'IconPark') {
|
|||
|
return {
|
|||
|
name,
|
|||
|
from: '@icon-park/vue-next/es/all'
|
|||
|
}
|
|||
|
}
|
|||
|
return undefined
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
dirs: ['src/components'],
|
|||
|
extensions: ['vue']
|
|||
|
})
|
|||
|
],
|
|||
|
css: {
|
|||
|
preprocessorOptions: {
|
|||
|
scss: { charset: false }
|
|||
|
// less: {
|
|||
|
// modifyVars: {
|
|||
|
// 'arcoblue-1': '#E8FAFF',
|
|||
|
// 'arcoblue-2': '#B0E0F2',
|
|||
|
// 'arcoblue-3': '#7DC5E4',
|
|||
|
// 'arcoblue-4': '#4EA9D7',
|
|||
|
// 'arcoblue-5': '#258DC9',
|
|||
|
// 'arcoblue-6': '#0071bc',
|
|||
|
// 'arcoblue-7': '#005BA0',
|
|||
|
// 'arcoblue-8': '#004784',
|
|||
|
// 'arcoblue-9': '#003468',
|
|||
|
// 'arcoblue-10': '#00244D'
|
|||
|
// },
|
|||
|
// javascriptEnabled: true
|
|||
|
// }
|
|||
|
}
|
|||
|
},
|
|||
|
resolve: {
|
|||
|
alias: {
|
|||
|
'@': resolve(__dirname, 'src') // 设置 `@` 指向 `src` 目录
|
|||
|
}
|
|||
|
},
|
|||
|
build: {
|
|||
|
manifest: true,
|
|||
|
cssCodeSplit: true, // 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
|
|||
|
sourcemap: false, // 构建后是否生成 source map 文件。如果为 true,将会创建一个独立的 source map 文件
|
|||
|
target: 'modules', // 设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——'modules' 还可设置为 'es2015' 'es2016'等
|
|||
|
chunkSizeWarningLimit: 550, // 单位kb 打包后文件大小警告的限制 (文件大于此此值会出现警告)
|
|||
|
assetsInlineLimit: 4096, // 单位字节(1024等于1kb) 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项。
|
|||
|
minify: 'terser', // 'terser' 相对较慢,但大多数情况下构建后的文件体积更小。'esbuild' 最小化混淆更快但构建后的文件相对更大。
|
|||
|
terserOptions: {
|
|||
|
compress: {
|
|||
|
// eslint-disable-next-line camelcase
|
|||
|
drop_console: true, // 生产环境去除console
|
|||
|
// eslint-disable-next-line camelcase
|
|||
|
drop_debugger: true // 生产环境去除debugger
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
server: {
|
|||
|
host: '0.0.0.0',
|
|||
|
port: 4000, // 设置服务启动端口号
|
|||
|
open: true, // 设置服务启动时是否自动打开浏览器
|
|||
|
cors: true, // 允许跨域
|
|||
|
// 设置代理,根据我们项目实际情况配置
|
|||
|
proxy: {
|
|||
|
// 项目根目录新建 .env.development 文件,填入 VITE_BASE_URL=http://xxx
|
|||
|
'/webapi': {
|
|||
|
target: loadEnv(config.mode, process.cwd()).VITE_HTTP_BASE_URL || 'http://127.0.0.1:8020',
|
|||
|
changeOrigin: true,
|
|||
|
secure: false,
|
|||
|
rewrite: (path) => path.replace('/webapi/', '/')
|
|||
|
},
|
|||
|
'/sys/file': {
|
|||
|
target: loadEnv(config.mode, process.cwd()).VITE_HTTP_BASE_URL || 'http://127.0.0.1:8020',
|
|||
|
changeOrigin: true,
|
|||
|
secure: false,
|
|||
|
rewrite: (path) => path
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
})
|
|||
|
}
|