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

107 lines
3.0 KiB

import { ConfigEnv, loadEnv, UserConfig } from 'vite'
4 years ago
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import legacy from '@vitejs/plugin-legacy'
4 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 => {
4 years ago
// 环境变量
const { VITE_BASE_URL } = loadEnv(mode, CWD)
4 years ago
return {
css: {
modules: {
localsConvention: 'camelCase' // 默认只支持驼峰,修改为同时支持横线和驼峰
}
},
plugins: [
vue(),
vueJsx(),
WindiCSS(),
legacy({
targets: ['defaults', 'not IE 11']
}),
4 years ago
ViteComponents({
// 自动导入组件(还不够完善,可能会有样式丢失)
4 years ago
// valid file extensions for components.
extensions: ['vue', 'tsx'],
customComponentResolvers: [ElementPlusResolver(), VantResolver()]
}),
styleImport({
// 手动导入组件
4 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` 目录
}
},
base: VITE_BASE_URL, // 设置打包路径
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`]
}
}
}
},
4 years ago
optimizeDeps: {
include: [
'vue',
'vue-router',
'@vueuse/core',
'element-plus',
'vant',
'lodash',
'vuedraggable/src/vuedraggable'
],
4 years ago
exclude: ['vue-demi']
},
server: {
port: 10086, // 设置服务启动端口号
4 years ago
open: false, // 设置服务启动时是否自动打开浏览器
cors: true // 允许跨域
// 设置代理,根据我们项目实际情况配置
// proxy: {
// '/api': {
// target: 'http://xxx.xxx.xxx.xxx:x000',
// changeOrigin: true,
// secure: false,
// rewrite: (path) => path.replace('/api/', '/')
// }
// },
}
}
}