2021-09-30 19:26:30 +08:00
|
|
|
import path from 'path'
|
|
|
|
import Inspect from 'vite-plugin-inspect'
|
|
|
|
import { defineConfig } from 'vite'
|
2022-02-11 11:39:49 +08:00
|
|
|
import DefineOptions from 'unplugin-vue-define-options/vite'
|
2021-12-12 17:54:21 +08:00
|
|
|
import WindiCSS from 'vite-plugin-windicss'
|
2022-01-24 02:34:06 +08:00
|
|
|
import mkcert from 'vite-plugin-mkcert'
|
2022-01-18 06:33:53 +08:00
|
|
|
import glob from 'fast-glob'
|
2022-02-11 12:10:56 +08:00
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
2021-12-31 16:30:35 +08:00
|
|
|
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
import Icons from 'unplugin-icons/vite'
|
|
|
|
import IconsResolver from 'unplugin-icons/resolver'
|
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
import { getPackageDependencies } from '../build/utils/pkg'
|
|
|
|
import { epPackage } from '../build/utils/paths'
|
2021-09-30 19:26:30 +08:00
|
|
|
import { projRoot } from './.vitepress/utils/paths'
|
|
|
|
import type { Alias } from 'vite'
|
|
|
|
|
|
|
|
const alias: Alias[] = []
|
|
|
|
if (process.env.DOC_ENV !== 'production') {
|
|
|
|
alias.push(
|
|
|
|
{
|
2021-10-29 11:23:18 +08:00
|
|
|
find: /^element-plus(\/(es|lib))?$/,
|
2021-09-30 19:26:30 +08:00
|
|
|
replacement: path.resolve(projRoot, 'packages/element-plus/index.ts'),
|
|
|
|
},
|
|
|
|
{
|
2021-10-29 11:23:18 +08:00
|
|
|
find: /^element-plus\/(es|lib)\/(.*)$/,
|
2021-09-30 19:26:30 +08:00
|
|
|
replacement: `${path.resolve(projRoot, 'packages')}/$2`,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
export default async () => {
|
2022-01-20 15:31:33 +08:00
|
|
|
const { dependencies } = getPackageDependencies(epPackage)
|
2022-01-18 06:33:53 +08:00
|
|
|
const optimizeDeps = [
|
|
|
|
'vue',
|
|
|
|
'@vue/shared',
|
|
|
|
'markdown-it',
|
|
|
|
'clipboard-copy',
|
|
|
|
'axios',
|
|
|
|
'nprogress',
|
2022-01-20 15:31:33 +08:00
|
|
|
...dependencies,
|
2022-01-18 06:33:53 +08:00
|
|
|
]
|
|
|
|
optimizeDeps.push(
|
|
|
|
...(
|
2022-02-08 10:37:21 +08:00
|
|
|
await glob(['dayjs/plugin/*.js'], {
|
2022-01-18 06:33:53 +08:00
|
|
|
cwd: path.resolve(projRoot, 'node_modules'),
|
|
|
|
onlyFiles: true,
|
|
|
|
})
|
|
|
|
).map((file) => file.replace(/\.js$/, ''))
|
|
|
|
)
|
|
|
|
|
|
|
|
return defineConfig({
|
|
|
|
server: {
|
|
|
|
host: true,
|
2022-01-25 16:57:25 +08:00
|
|
|
https: !!process.env.HTTPS,
|
2022-01-18 06:33:53 +08:00
|
|
|
fs: {
|
|
|
|
allow: [projRoot],
|
|
|
|
},
|
2021-09-30 19:26:30 +08:00
|
|
|
},
|
2022-01-18 06:33:53 +08:00
|
|
|
resolve: {
|
|
|
|
alias,
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks: {
|
|
|
|
windicss: ['windicss'],
|
|
|
|
},
|
2021-12-12 17:54:21 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 06:33:53 +08:00
|
|
|
plugins: [
|
2022-02-11 12:10:56 +08:00
|
|
|
vueJsx(),
|
2022-02-11 11:39:49 +08:00
|
|
|
DefineOptions(),
|
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
// https://github.com/antfu/unplugin-vue-components
|
|
|
|
Components({
|
|
|
|
// custom resolvers
|
|
|
|
resolvers: [
|
|
|
|
// auto import icons
|
|
|
|
// https://github.com/antfu/unplugin-icons
|
|
|
|
IconsResolver(),
|
|
|
|
],
|
|
|
|
}),
|
2021-12-31 16:30:35 +08:00
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
// https://github.com/antfu/unplugin-icons
|
|
|
|
Icons({
|
|
|
|
autoInstall: true,
|
|
|
|
}),
|
|
|
|
WindiCSS(),
|
|
|
|
Inspect(),
|
2022-01-24 02:34:06 +08:00
|
|
|
mkcert(),
|
2021-11-19 20:22:16 +08:00
|
|
|
],
|
2022-01-18 06:33:53 +08:00
|
|
|
optimizeDeps: {
|
|
|
|
include: optimizeDeps,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|