From 042c63883c46b943e81077ec77c0cd1bb08c4d8a Mon Sep 17 00:00:00 2001 From: xcy960815 <18763006837@163.com> Date: Thu, 29 Feb 2024 16:24:39 +0800 Subject: [PATCH] feat(vite): update vite configuration (#6102) --- vite.config.js | 38 -------------------------------------- vite.config.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 38 deletions(-) delete mode 100644 vite.config.js create mode 100644 vite.config.ts diff --git a/vite.config.js b/vite.config.js deleted file mode 100644 index 2fafb2e228..0000000000 --- a/vite.config.js +++ /dev/null @@ -1,38 +0,0 @@ -import { defineConfig } from 'vite'; -import { deepMix } from '@antv/util'; - -const { LINK, MODULE } = process.env; - -if (LINK === '1' && !MODULE) { - throw new Error( - `Please specify MODULE, for example: $ MODULE=@antv/component npm run dev:link.`, - ); -} - -const linkOptions = - LINK === '1' - ? { - server: { - watch: { - ignored: [`!**/node_modules/${MODULE}/**`], - }, - }, - optimizeDeps: { - exclude: [`${MODULE}`], - }, - } - : {}; - -export default defineConfig( - deepMix( - { - root: './__tests__/', - server: { - port: 8080, - open: '/', - }, - build: { outDir: '../' }, - }, - linkOptions, - ), -); diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000000..55013f298c --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,49 @@ +import { defineConfig } from 'vite'; +import type { UserConfig } from 'vite'; +import { deepMix } from '@antv/util'; +const { LINK, MODULE } = process.env; + +if (LINK === '1' && !MODULE) { + throw new Error( + `Please specify MODULE, for example: $ MODULE=@antv/component npm run dev:link.`, + ); +} + +/** + * @desc Deeply merge user config into default config + * @link https://vitejs.dev/config/ + * @type {import('vite').UserConfig} + */ +const baseOptions: UserConfig = { + root: './__tests__/', + server: { + port: 8080, + open: '/', + }, + build: { outDir: '../' }, +}; + +/** + * @desc Link configuration + * @link https://vitejs.dev/config/ + * @type {import('vite').UserConfig} + */ +const linkOptions: UserConfig = { + server: { + watch: { + ignored: [`!**/node_modules/${MODULE}/**`], + }, + }, + optimizeDeps: { + exclude: [`${MODULE}`], + }, +}; + +/** + * @desc Vite configuration + * @link https://vitejs.dev/config/ + * @type {import('vite').UserConfig} + */ +export default defineConfig( + deepMix(baseOptions, LINK === '1' ? linkOptions : {}), +);