vite-vue3-lowcode/vite.config.ts

108 lines
3.1 KiB
TypeScript
Raw Normal View History

2021-05-12 11:53:17 +08:00
import { ConfigEnv, loadEnv, UserConfig } from 'vite'
2021-05-04 21:54:05 +08:00
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
2021-05-20 09:02:51 +08:00
import legacy from '@vitejs/plugin-legacy'
2021-05-04 21:54:05 +08:00
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()
2021-05-26 22:15:13 +08:00
const prefix = `monaco-editor/esm/vs`
2021-05-12 11:53:17 +08:00
// https://cn.vitejs.dev/config/
export default ({ mode }: ConfigEnv): UserConfig => {
2021-05-04 21:54:05 +08:00
// 环境变量
2021-05-12 11:53:17 +08:00
const { VITE_BASE_URL } = loadEnv(mode, CWD)
2021-05-04 21:54:05 +08:00
return {
2021-07-04 17:04:10 +08:00
base: VITE_BASE_URL, // 设置打包路径
2021-05-04 21:54:05 +08:00
css: {
modules: {
localsConvention: 'camelCase' // 默认只支持驼峰,修改为同时支持横线和驼峰
}
},
plugins: [
vue(),
vueJsx(),
WindiCSS(),
2021-05-20 09:02:51 +08:00
legacy({
targets: ['defaults', 'not IE 11']
}),
2021-05-04 21:54:05 +08:00
ViteComponents({
2021-06-24 01:38:30 +08:00
globalComponentsDeclaration: true,
2021-05-12 11:53:17 +08:00
// 自动导入组件(还不够完善,可能会有样式丢失)
2021-05-04 21:54:05 +08:00
// valid file extensions for components.
2021-06-24 01:38:30 +08:00
extensions: ['vue', 'tsx', 'js'],
2021-05-04 21:54:05 +08:00
customComponentResolvers: [ElementPlusResolver(), VantResolver()]
}),
styleImport({
2021-05-12 11:53:17 +08:00
// 手动导入组件
2021-05-04 21:54:05 +08:00
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` 目录
}
},
2021-05-06 00:35:05 +08:00
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
preview: resolve(__dirname, 'preview/index.html')
2021-05-26 22:15:13 +08:00
},
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`]
}
2021-05-06 00:35:05 +08:00
}
}
},
2021-05-04 21:54:05 +08:00
optimizeDeps: {
2021-05-06 00:35:05 +08:00
include: [
'vue',
'vue-router',
'@vueuse/core',
'element-plus',
'vant',
'lodash',
2021-05-20 09:02:51 +08:00
'vuedraggable/src/vuedraggable'
2021-05-06 00:35:05 +08:00
],
2021-05-04 21:54:05 +08:00
exclude: ['vue-demi']
},
server: {
2021-05-26 22:15:13 +08:00
port: 10086, // 设置服务启动端口号
2021-05-04 21:54:05 +08:00
open: false, // 设置服务启动时是否自动打开浏览器
2021-07-04 17:04:10 +08:00
cors: true, // 允许跨域
2021-05-04 21:54:05 +08:00
2021-07-04 17:04:10 +08:00
// 设置代理,根据项目实际情况配置
proxy: {
'/api': {
target: 'http://29135jo738.zicp.vip/api/v1',
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace('/api/', '/')
}
}
2021-05-04 21:54:05 +08:00
}
}
}