加入 Gitee
與超過 1200 萬 開發者一起發現、參與優秀開源項目,私有倉庫也完全免費 :)
免費加入
文件
克隆/下載
vite.config.ts 1.69 KB
一鍵複製 編輯 原始數據 按行查看 歷史
import type { UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import { viteMockServe } from 'vite-plugin-mock'
import autoComponents from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import purgeIcons from 'vite-plugin-purge-icons'
import eslintPlugin from '@nabla/vite-plugin-eslint'
import legacy from '@vitejs/plugin-legacy'
import defineOptions from 'unplugin-vue-define-options/vite'
import unocss from 'unocss/vite'
// https://vitejs.dev/config/
function getPlugins(command: string) {
return [
vue(),
unocss(),
defineOptions(),
vueJsx(),
purgeIcons(),
autoComponents({
dirs: ['src/components', 'src/layouts'],
resolvers: [NaiveUiResolver()],
dts: true
}),
eslintPlugin({
shouldLint: (path) => /\/src\/[^\?\r\n]*\.(vue|tsx?)$/.test(path),
eslintOptions: {
cache: false
}
}),
viteMockServe({
mockPath: 'src/mock',
localEnabled: command === 'serve',
prodEnabled: command !== 'serve',
// 这样可以控制关闭mock的时候不让mock打包到最终代码内
injectCode: `
import { setupProdMockServer } from './mock/useMock'
setupProdMockServer()
`
}),
legacy({
targets: ['defaults', 'not IE 11']
})
]
}
export default ({ command }): UserConfigExport => ({
plugins: getPlugins(command),
resolve: {
alias: [
{
find: '@',
replacement: path.resolve(__dirname, './src/')
}
]
},
server: {
port: 8000,
host: true,
open: true
},
build: {
sourcemap: false
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化