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-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
|
2024-11-08 09:38:27 +08:00
|
|
|
const optimizeDeps = await glob(['dayjs/(locale|plugin)/*.js'], {
|
|
|
|
cwd: path.resolve(projRoot, 'node_modules'),
|
|
|
|
})
|
2021-10-29 11:23:18 +08:00
|
|
|
|
|
|
|
return {
|
2024-10-01 08:45:25 +08:00
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
scss: {
|
|
|
|
// additionalData: `@use "/styles/custom.scss" as *;`,
|
|
|
|
silenceDeprecations: ['legacy-js-api'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-29 11:23:18 +08:00
|
|
|
resolve: {
|
|
|
|
alias: [
|
|
|
|
{
|
|
|
|
find: /^element-plus(\/(es|lib))?$/,
|
|
|
|
replacement: path.resolve(epRoot, 'index.ts'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: /^element-plus\/(es|lib)\/(.*)$/,
|
|
|
|
replacement: `${pkgRoot}/$2`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
server: {
|
2024-11-08 09:38:27 +08:00
|
|
|
port: 3000,
|
2021-10-29 11:23:18 +08:00
|
|
|
host: true,
|
2024-11-08 09:38:27 +08:00
|
|
|
https: !!env.HTTPS ? {} : false,
|
2021-10-29 11:23:18 +08:00
|
|
|
},
|
2024-07-08 14:31:23 +08:00
|
|
|
build: {
|
|
|
|
sourcemap: true,
|
|
|
|
},
|
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}/**`,
|
2024-11-08 09:38:27 +08:00
|
|
|
resolvers: ElementPlusResolver({
|
|
|
|
version: '2.0.0-dev.1',
|
|
|
|
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
|
|
|
})
|