2021-09-30 19:26:30 +08:00
|
|
|
import path from 'path'
|
|
|
|
import Inspect from 'vite-plugin-inspect'
|
2022-03-01 21:38:52 +08:00
|
|
|
import { defineConfig, loadEnv } from 'vite'
|
2022-09-16 22:57:41 +08:00
|
|
|
import VueMacros from 'unplugin-vue-macros/vite'
|
2022-03-22 17:16:46 +08:00
|
|
|
import UnoCSS from 'unocss/vite'
|
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-03-15 19:23:38 +08:00
|
|
|
import {
|
2022-05-02 15:15:47 +08:00
|
|
|
docPackage,
|
2022-03-15 19:23:38 +08:00
|
|
|
epPackage,
|
|
|
|
getPackageDependencies,
|
|
|
|
projRoot,
|
2022-04-09 04:32:01 +08:00
|
|
|
} from '@element-plus/build-utils'
|
2022-04-08 00:40:25 +08:00
|
|
|
import { MarkdownTransform } from './.vitepress/plugins/markdown-transform'
|
2022-04-09 04:32:01 +08:00
|
|
|
|
2021-09-30 19:26:30 +08:00
|
|
|
import type { Alias } from 'vite'
|
|
|
|
|
2022-04-10 23:58:20 +08:00
|
|
|
const alias: Alias[] = [
|
|
|
|
{
|
|
|
|
find: '~/',
|
|
|
|
replacement: `${path.resolve(__dirname, './.vitepress/vitepress')}/`,
|
|
|
|
},
|
|
|
|
]
|
2021-09-30 19:26:30 +08:00
|
|
|
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-03-01 21:38:52 +08:00
|
|
|
export default defineConfig(async ({ mode }) => {
|
|
|
|
const env = loadEnv(mode, process.cwd(), '')
|
2022-05-02 15:15:47 +08:00
|
|
|
|
|
|
|
const { dependencies: epDeps } = getPackageDependencies(epPackage)
|
|
|
|
const { dependencies: docsDeps } = getPackageDependencies(docPackage)
|
|
|
|
|
|
|
|
const optimizeDeps = [...new Set([...epDeps, ...docsDeps])].filter(
|
|
|
|
(dep) =>
|
|
|
|
!dep.startsWith('@types/') &&
|
|
|
|
!['@element-plus/metadata', 'element-plus'].includes(dep)
|
|
|
|
)
|
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
optimizeDeps.push(
|
2022-04-08 14:17:44 +08:00
|
|
|
...(await glob(['dayjs/plugin/*.js'], {
|
|
|
|
cwd: path.resolve(projRoot, 'node_modules'),
|
|
|
|
onlyFiles: true,
|
|
|
|
}))
|
2022-01-18 06:33:53 +08:00
|
|
|
)
|
|
|
|
|
2022-03-01 21:38:52 +08:00
|
|
|
return {
|
2022-01-18 06:33:53 +08:00
|
|
|
server: {
|
|
|
|
host: true,
|
2022-03-01 21:38:52 +08:00
|
|
|
https: !!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,
|
|
|
|
},
|
|
|
|
plugins: [
|
2022-09-16 22:57:41 +08:00
|
|
|
VueMacros({
|
|
|
|
setupComponent: false,
|
|
|
|
setupSFC: false,
|
|
|
|
plugins: {
|
|
|
|
vueJsx: vueJsx(),
|
|
|
|
},
|
|
|
|
}),
|
2022-02-11 11:39:49 +08:00
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
// https://github.com/antfu/unplugin-vue-components
|
|
|
|
Components({
|
2022-04-27 10:47:15 +08:00
|
|
|
dirs: ['.vitepress/vitepress/components'],
|
|
|
|
|
|
|
|
allowOverrides: true,
|
|
|
|
|
2022-01-18 06:33:53 +08:00
|
|
|
// custom resolvers
|
|
|
|
resolvers: [
|
|
|
|
// auto import icons
|
|
|
|
// https://github.com/antfu/unplugin-icons
|
|
|
|
IconsResolver(),
|
|
|
|
],
|
2022-05-04 22:58:35 +08:00
|
|
|
|
|
|
|
// allow auto import and register components used in markdown
|
|
|
|
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
2022-01-18 06:33:53 +08:00
|
|
|
}),
|
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,
|
|
|
|
}),
|
2022-03-22 17:16:46 +08:00
|
|
|
UnoCSS(),
|
2022-04-08 00:40:25 +08:00
|
|
|
MarkdownTransform(),
|
2022-01-18 06:33:53 +08:00
|
|
|
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,
|
|
|
|
},
|
2022-03-01 21:38:52 +08:00
|
|
|
}
|
|
|
|
})
|