element-plus/docs/vite.config.ts

130 lines
3.2 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 { VitePWA } from 'vite-plugin-pwa'
import {
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(), '')
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',
...dependencies,
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(),
],
}),
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(),
VitePWA({
outDir: '.vitepress/dist',
includeAssets: ['images/**'],
manifest: {
id: '/',
name: 'Element Plus',
short_name: 'Element Plus',
description:
'a Vue 3 based component library for designers and developers',
icons: [
{
src: 'android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
theme_color: '#ffffff',
background_color: '#ffffff',
display: 'standalone',
},
}),
],
2022-01-18 06:33:53 +08:00
optimizeDeps: {
include: optimizeDeps,
},
2022-03-01 21:38:52 +08:00
}
})