element-plus/play/vite.config.ts

86 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-10-26 17:09:14 +08:00
import path from 'path'
2022-03-01 21:38:52 +08:00
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Inspect from 'vite-plugin-inspect'
import mkcert from 'vite-plugin-mkcert'
import glob from 'fast-glob'
import VueMacros from 'unplugin-vue-macros/vite'
import esbuild from 'rollup-plugin-esbuild'
2022-04-10 13:47:54 +08:00
import {
epPackage,
epRoot,
getPackageDependencies,
pkgRoot,
projRoot,
} from '@element-plus/build-utils'
import type { Plugin } from 'vite'
import './vite.init'
const esbuildPlugin = (): Plugin => ({
...esbuild({
target: 'chrome64',
loaders: {
'.vue': 'js',
},
}),
enforce: 'post',
})
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
const optimizeDeps = (
await glob(['dayjs/(locale|plugin)/*.js'], {
cwd: path.resolve(projRoot, 'node_modules'),
})
).map((dep) => dep.replace(/\.js$/, ''))
return {
resolve: {
alias: [
{
find: /^element-plus(\/(es|lib))?$/,
replacement: path.resolve(epRoot, 'index.ts'),
},
{
find: /^element-plus\/(es|lib)\/(.*)$/,
replacement: `${pkgRoot}/$2`,
},
],
},
server: {
host: true,
2022-03-01 21:38:52 +08:00
https: !!env.HTTPS,
},
plugins: [
VueMacros({
setupComponent: false,
setupSFC: false,
plugins: {
vue: vue(),
vueJsx: vueJsx(),
},
}),
esbuildPlugin(),
Components({
include: `${__dirname}/**`,
resolvers: ElementPlusResolver({ importStyle: 'sass' }),
dts: false,
}),
mkcert(),
Inspect(),
2021-10-26 17:09:14 +08:00
],
optimizeDeps: {
include: ['vue', '@vue/shared', ...dependencies, ...optimizeDeps],
},
esbuild: {
target: 'chrome64',
},
}
})