From 04db2fb7cabbb3c653b5564f211dc81f388be053 Mon Sep 17 00:00:00 2001 From: Kirk Lin Date: Fri, 13 Oct 2023 10:20:51 +0800 Subject: [PATCH] feat: add `unplugin-config` plugin --- package.json | 2 ++ pnpm-lock.yaml | 52 ++++++++++++++++++++++++++++++++++++++++++- types/components.d.ts | 1 - vite.config.ts | 22 ++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 85e633e..f355f25 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "crypto-js": "^4.1.1", "dayjs": "^1.11.10", "destr": "^2.0.1", + "dotenv": "^16.3.1", "iso-639-1": "^3.1.0", "lodash-es": "^4.17.21", "nprogress": "^0.2.0", @@ -73,6 +74,7 @@ "unocss-preset-chinese": "^0.3.0", "unocss-preset-ease": "^0.0.3", "unplugin-auto-import": "^0.16.6", + "unplugin-config": "^0.1.3", "unplugin-icons": "^0.17.0", "unplugin-vue-components": "^0.25.2", "vite": "^4.4.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5f0f541..929f1e8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ dependencies: destr: specifier: ^2.0.1 version: 2.0.1 + dotenv: + specifier: ^16.3.1 + version: 16.3.1 iso-639-1: specifier: ^3.1.0 version: 3.1.0 @@ -139,6 +142,9 @@ devDependencies: unplugin-auto-import: specifier: ^0.16.6 version: 0.16.6(@vueuse/core@10.5.0)(rollup@2.79.1) + unplugin-config: + specifier: ^0.1.3 + version: 0.1.3(rollup@2.79.1)(vite@4.4.11) unplugin-icons: specifier: ^0.17.0 version: 0.17.0 @@ -2160,7 +2166,6 @@ packages: /@kirklin/logger@0.0.2: resolution: {integrity: sha512-CGZ9HGmHGTcGnU8CDQm7RR7hZgxLyRHTIFpS1FDCQkVaipdL/poq72ibpKqqQflomgKRCYV6GReP7ZXEZeDx1w==} - dev: false /@kirklin/reset-css@0.0.3: resolution: {integrity: sha512-EUfxCc0U8iIn4hwhtsOha6uYKul839pyol4Yt5FJtLT8BH/F9MLMkik6KkKHhvInk8nVu4flSsFBGn/OZuu74g==} @@ -3834,6 +3839,11 @@ packages: is-obj: 2.0.0 dev: true + /dotenv@16.3.1: + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} + engines: {node: '>=12'} + dev: false + /duplexer@0.1.2: resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} dev: true @@ -4772,6 +4782,10 @@ packages: whatwg-encoding: 2.0.0 dev: true + /html-entities@2.4.0: + resolution: {integrity: sha512-igBTJcNNNhvZFRtm8uA6xMY6xYleeDwn3PeBCkDz7tHttv4F2hsDI2aPgNERWzvRcNYHNT3ymRaQzllmXj4YsQ==} + dev: true + /html-escaper@2.0.2: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} dev: true @@ -6999,6 +7013,42 @@ packages: - rollup dev: true + /unplugin-config@0.1.3(rollup@2.79.1)(vite@4.4.11): + resolution: {integrity: sha512-VEIIodczqg2uDyn3TvKFz2s28bAyfM2bgTP2k3LfEgiv93BEtiVl/X1lmB+lBLiFURADdhu6PRfkAsWmwr/Sjw==} + peerDependencies: + '@nuxt/kit': ^3 + '@nuxt/schema': ^3 + esbuild: '*' + rollup: ^3 + vite: '>=3' + webpack: ^4 || ^5 + peerDependenciesMeta: + '@nuxt/kit': + optional: true + '@nuxt/schema': + optional: true + esbuild: + optional: true + rollup: + optional: true + vite: + optional: true + webpack: + optional: true + dependencies: + '@kirklin/logger': 0.0.2 + html-entities: 2.4.0 + jsdom: 22.1.0 + rollup: 2.79.1 + unplugin: 1.5.0 + vite: 4.4.11(@types/node@20.8.4)(sass@1.69.3) + transitivePeerDependencies: + - bufferutil + - canvas + - supports-color + - utf-8-validate + dev: true + /unplugin-icons@0.17.0: resolution: {integrity: sha512-gMv66eY/Hj64heM55XrfDH3LUCWI51mtkBVUPVl9VkpvLgAYhdVe9nRuzu6p+idmCLSQVq7xiPxQcD4aXCgW5A==} peerDependencies: diff --git a/types/components.d.ts b/types/components.d.ts index e98e6ca..de62bc7 100644 --- a/types/components.d.ts +++ b/types/components.d.ts @@ -7,7 +7,6 @@ export {} declare module 'vue' { export interface GlobalComponents { - BVIcon: typeof import('./../src/components/Icon/BVIcon.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] UnoCSSIconButton: typeof import('./../src/components/Icon/UnoCSSIconButton.vue')['default'] diff --git a/vite.config.ts b/vite.config.ts index 80c520f..e9f687b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,11 +9,21 @@ import Icons from "unplugin-icons/vite"; import { FileSystemIconLoader } from "unplugin-icons/loaders"; import IconsResolver from "unplugin-icons/resolver"; import { VitePWA } from "vite-plugin-pwa"; +import GenerateConfig from "unplugin-config/vite"; // vite.config.ts import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"; import UnoCss from "unocss/vite"; +// This constant defines the name of the configuration file that will be used in the production environment +const GLOB_CONFIG_FILE_NAME = "_app.config.js"; + +// This constant sets the output directory for the Vite package +const OUTPUT_DIR = "dist"; + +// This constant sets the name of the application +const APP_NAME = "boot-vant"; + // https://vitejs.dev/config/ export default defineConfig({ server: { @@ -113,6 +123,18 @@ export default defineConfig({ // https://github.com/unocss/unocss // see unocss.config.ts for config UnoCss(), + + GenerateConfig({ + appName: APP_NAME, + envVariables: { + prefix: "VITE_GLOB_", + }, + configFile: { + generate: true, + fileName: GLOB_CONFIG_FILE_NAME, + outputDir: OUTPUT_DIR, + }, + }), ], resolve: { alias: {