You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vite-vue3-lowcode/vite.config.ts

108 lines
3.1 KiB

import { ConfigEnv, loadEnv, UserConfig } from 'vite'
3 years ago
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import legacy from '@vitejs/plugin-legacy'
3 years ago
import { resolve } from 'path'
import ViteComponents, { ElementPlusResolver, VantResolver } from 'vite-plugin-components'
import styleImport from 'vite-plugin-style-import'
import WindiCSS from 'vite-plugin-windicss'
const CWD = process.cwd()
const prefix = `monaco-editor/esm/vs`
// https://cn.vitejs.dev/config/
export default ({ mode }: ConfigEnv): UserConfig => {
3 years ago
// 环境变量
const { VITE_BASE_URL } = loadEnv(mode, CWD)
3 years ago
return {
base: VITE_BASE_URL, // 设置打包路径
3 years ago
css: {
modules: {
localsConvention: 'camelCase' // 默认只支持驼峰,修改为同时支持横线和驼峰
}
},
plugins: [
vue(),
vueJsx(),
WindiCSS(),
legacy({
targets: ['defaults', 'not IE 11']
}),
3 years ago
ViteComponents({
globalComponentsDeclaration: true,
// 自动导入组件(还不够完善,可能会有样式丢失)
3 years ago
// valid file extensions for components.
extensions: ['vue', 'tsx', 'js'],
3 years ago
customComponentResolvers: [ElementPlusResolver(), VantResolver()]
}),
styleImport({
// 手动导入组件
3 years ago
libs: [
{
libraryName: 'element-plus',
esModule: true,
ensureStyleFile: true,
resolveStyle: (name) => {
name = name.slice(3)
return `element-plus/packages/theme-chalk/src/${name}.scss`
},
resolveComponent: (name) => {
return `element-plus/lib/${name}`
}
}
]
})
],
resolve: {
alias: {
'@': resolve(__dirname, 'src') // 设置 `@` 指向 `src` 目录
}
},
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
preview: resolve(__dirname, 'preview/index.html')
},
output: {
manualChunks: {
jsonWorker: [`${prefix}/language/json/json.worker`],
cssWorker: [`${prefix}/language/css/css.worker`],
htmlWorker: [`${prefix}/language/html/html.worker`],
tsWorker: [`${prefix}/language/typescript/ts.worker`],
editorWorker: [`${prefix}/editor/editor.worker`]
}
}
}
},
3 years ago
optimizeDeps: {
include: [
'vue',
'vue-router',
'@vueuse/core',
'element-plus',
'vant',
'lodash',
'vuedraggable/src/vuedraggable'
],
3 years ago
exclude: ['vue-demi']
},
server: {
port: 10086, // 设置服务启动端口号
3 years ago
open: false, // 设置服务启动时是否自动打开浏览器
cors: true, // 允许跨域
3 years ago
// 设置代理,根据项目实际情况配置
proxy: {
'/api': {
target: 'http://29135jo738.zicp.vip/api/v1',
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace('/api/', '/')
}
}
3 years ago
}
}
}