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'
|
2021-09-17 16:42:20 +08:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
2022-02-11 12:10:56 +08:00
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
2021-10-22 15:59:29 +08:00
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
2021-10-29 11:23:18 +08:00
|
|
|
import Inspect from 'vite-plugin-inspect'
|
2022-01-24 02:34:06 +08:00
|
|
|
import mkcert from 'vite-plugin-mkcert'
|
2021-10-29 11:23:18 +08:00
|
|
|
import glob from 'fast-glob'
|
2022-09-16 22:57:41 +08:00
|
|
|
import VueMacros from 'unplugin-vue-macros/vite'
|
2022-02-21 09:15:23 +08:00
|
|
|
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'
|
2022-09-16 22:57:41 +08:00
|
|
|
import type { Plugin } from 'vite'
|
2021-09-23 08:12:37 +08:00
|
|
|
import './vite.init'
|
2021-09-17 16:42:20 +08:00
|
|
|
|
2022-09-16 22:57:41 +08:00
|
|
|
const esbuildPlugin = (): Plugin => ({
|
2022-02-21 09:15:23 +08:00
|
|
|
...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(), '')
|
2022-04-11 00:29:07 +08:00
|
|
|
let { dependencies } = getPackageDependencies(epPackage)
|
|
|
|
dependencies = dependencies.filter((dep) => !dep.startsWith('@types/')) // exclude dts deps
|
2021-10-29 11:23:18 +08:00
|
|
|
const optimizeDeps = (
|
2022-02-08 10:37:21 +08:00
|
|
|
await glob(['dayjs/(locale|plugin)/*.js'], {
|
2021-10-29 11:23:18 +08:00
|
|
|
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,
|
2021-10-29 11:23:18 +08:00
|
|
|
},
|
|
|
|
plugins: [
|
2022-09-16 22:57:41 +08:00
|
|
|
VueMacros({
|
|
|
|
setupComponent: false,
|
|
|
|
setupSFC: false,
|
|
|
|
plugins: {
|
|
|
|
vue: vue(),
|
|
|
|
vueJsx: vueJsx(),
|
|
|
|
},
|
|
|
|
}),
|
2022-02-21 09:15:23 +08:00
|
|
|
esbuildPlugin(),
|
2021-10-29 11:23:18 +08:00
|
|
|
Components({
|
|
|
|
include: `${__dirname}/**`,
|
|
|
|
resolvers: ElementPlusResolver({ importStyle: 'sass' }),
|
2022-01-24 02:34:06 +08:00
|
|
|
dts: false,
|
2021-10-29 11:23:18 +08:00
|
|
|
}),
|
2022-01-24 02:34:06 +08:00
|
|
|
mkcert(),
|
2021-10-29 11:23:18 +08:00
|
|
|
Inspect(),
|
2021-10-26 17:09:14 +08:00
|
|
|
],
|
2021-10-29 11:23:18 +08:00
|
|
|
|
|
|
|
optimizeDeps: {
|
2022-01-24 02:34:06 +08:00
|
|
|
include: ['vue', '@vue/shared', ...dependencies, ...optimizeDeps],
|
2021-10-29 11:23:18 +08:00
|
|
|
},
|
2022-02-21 09:15:23 +08:00
|
|
|
esbuild: {
|
|
|
|
target: 'chrome64',
|
|
|
|
},
|
2021-10-29 11:23:18 +08:00
|
|
|
}
|
2021-09-17 16:42:20 +08:00
|
|
|
})
|