element-plus/docs/vite.config.ts

106 lines
2.6 KiB
TypeScript
Raw Normal View History

import path from 'path'
import Inspect from 'vite-plugin-inspect'
2022-03-01 21:38:52 +08:00
import { defineConfig, loadEnv } from 'vite'
import DefineOptions from 'unplugin-vue-define-options/vite'
import UnoCSS from 'unocss/vite'
import mkcert from 'vite-plugin-mkcert'
2022-01-18 06:33:53 +08:00
import glob from 'fast-glob'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import {
docPackage,
epPackage,
getPackageDependencies,
projRoot,
} from '@element-plus/build-utils'
import { MarkdownTransform } from './.vitepress/plugins/markdown-transform'
import type { Alias } from 'vite'
const alias: Alias[] = [
{
find: '~/',
replacement: `${path.resolve(__dirname, './.vitepress/vitepress')}/`,
},
]
if (process.env.DOC_ENV !== 'production') {
alias.push(
{
find: /^element-plus(\/(es|lib))?$/,
replacement: path.resolve(projRoot, 'packages/element-plus/index.ts'),
},
{
find: /^element-plus\/(es|lib)\/(.*)$/,
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(), '')
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(
...(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],
},
},
2022-01-18 06:33:53 +08:00
resolve: {
alias,
},
plugins: [
vueJsx(),
DefineOptions(),
2022-01-18 06:33:53 +08:00
// https://github.com/antfu/unplugin-vue-components
Components({
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(),
],
// allow auto import and register components used in markdown
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
2022-01-18 06:33:53 +08:00
}),
2022-01-18 06:33:53 +08:00
// https://github.com/antfu/unplugin-icons
Icons({
autoInstall: true,
}),
UnoCSS(),
MarkdownTransform(),
2022-01-18 06:33:53 +08:00
Inspect(),
mkcert(),
],
2022-01-18 06:33:53 +08:00
optimizeDeps: {
include: optimizeDeps,
},
2022-03-01 21:38:52 +08:00
}
})