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-02-11 11:39:49 +08:00
|
|
|
import DefineOptions from 'unplugin-vue-define-options/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 {
|
|
|
|
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'
|
|
|
|
|
|
|
|
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-03-01 21:38:52 +08:00
|
|
|
export default defineConfig(async ({ mode }) => {
|
|
|
|
const env = loadEnv(mode, process.cwd(), '')
|
2022-04-08 00:37:46 +08:00
|
|
|
let { dependencies } = getPackageDependencies(epPackage)
|
|
|
|
dependencies = dependencies.filter((dep) => !dep.startsWith('@types/')) // exclude dts deps
|
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-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-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,
|
|
|
|
}),
|
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
|
|
|
}
|
|
|
|
})
|