Vue2.7 + Vite+ Eslint、Stylelint、Commitlint 统一开发规范 + husky + lint-staged (git commit 时自动格式化代码) + Vue 全家桶集成 + Axios 封装及接口管理 https://juejin.cn/post/7118700020911570974
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.
 
 
 
 
 
 

108 lines
2.9 KiB

import vue from '@vitejs/plugin-vue2'
import legacy from '@vitejs/plugin-legacy'
import serverProxy from './build/proxy'
import { defineConfig, loadEnv } from 'vite'
import { pathResolve, wrapperEnv } from './build/utils'
// https://github.com/antfu/unplugin-vue-components#importing-from-ui-libraries
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import vitePluginImp from 'vite-plugin-imp'
// 修复antdv加载moment和require错误导致不兼容问题
import antdvFix from 'vite-plugin-antdv-fix'
const variablesLessPath = pathResolve('./src/styles/global/variables.less')
const utilsLessPath = pathResolve('./src/styles/global/utils.less')
// https://vitejs.dev/config/
export default ({ mode, command }) => {
const root = process.cwd()
const isBuild = command === 'build'
// 在 vite 配置文件中使用环境变量,需要通过 loadEnv 来加载
const env = loadEnv(mode, root)
const { VITE_PUBLIC_PATH, VITE_OUTPUT_DIR, VITE_PORT, VITE_LEGACY } =
wrapperEnv(env)
const plugins = [
antdvFix(),
vue(),
Components({
transformer: 'vue2', // vue2.7必需
resolvers: [AntDesignVueResolver()]
}),
vitePluginImp({
libList: [
{
libName: 'lodash',
libDirectory: '',
camel2DashComponentName: false
},
{
libName: 'ant-design-vue',
style(name) {
// use less
return `ant-design-vue/es/${name}/style/css.js`
}
}
]
})
]
/**
* vite 默认打包文件带有 ES6 语法,在旧版浏览器中是不支持的。
* 为了支持旧版浏览器,可以在 .env.production 中开启 VITE_LEGACY 设置
*/
if (isBuild && VITE_LEGACY) {
plugins.push(
legacy({
targets: ['defaults', 'IE 11']
})
)
}
return defineConfig({
root,
base: VITE_PUBLIC_PATH,
plugins,
resolve: {
alias: {
// @/xxxx => src/xxxx
'@': pathResolve('./src')
// 'rc-picker/es/generate/moment': 'rc-picker/es/generate/dayjs'
}
},
server: {
host: true,
port: VITE_PORT,
proxy: serverProxy
},
build: {
/**
* 最终构建的浏览器兼容目标
* https://www.vitejs.net/config/#build-target
*/
// target: 'es2015',
outDir: VITE_OUTPUT_DIR,
brotliSize: false, // 关闭 brotli 压缩大小报告,可提升构建速度
chunkSizeWarningLimit: 2000 // chunk 大小警告的限制(以 kbs 为单位)
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
hask: `
true;
@import (reference) "${variablesLessPath}";
@import (reference) "${utilsLessPath}";
`
},
javascriptEnabled: true
}
}
}
})
}