From f1dca76a3cc9c2fbb7b20eb3c94e15e1fb9de2f1 Mon Sep 17 00:00:00 2001 From: BrendanEichDisciple Date: Wed, 21 Aug 2024 20:36:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3sveltekit=20=E5=AD=90?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=9C=AA=E9=85=8D=E7=BD=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- .env.production | 2 +- package.json | 1 + pnpm-lock.yaml | 9 +++++++++ svelte.config.js | 10 +++++++++- vite.config.js | 3 +-- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.env.development b/.env.development index ad9e870..610db96 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ -VITE_BASE=/ +VITE_BASE='' VITE_BASE_URL=http://localhost:3000/api/v1 \ No newline at end of file diff --git a/.env.production b/.env.production index 1154699..46faa86 100644 --- a/.env.production +++ b/.env.production @@ -1,2 +1,2 @@ -VITE_BASE=/hospital/ +VITE_BASE=/hospital VITE_BASE_URL=http://localhost:3000/api/v1 \ No newline at end of file diff --git a/package.json b/package.json index 6d78453..142ccf4 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@types/eslint": "8.56.10", "autoprefixer": "^10.4.20", "clsx": "^2.1.1", + "dotenv": "^16.4.5", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.43.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a3a5f62..2541c5e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: clsx: specifier: ^2.1.1 version: 2.1.1 + dotenv: + specifier: ^16.4.5 + version: 16.4.5 eslint: specifier: ^8.56.0 version: 8.56.0 @@ -781,6 +784,10 @@ packages: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} engines: {node: '>=6.0.0'} + dotenv@16.4.5: + resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} + engines: {node: '>=12'} + earcut@3.0.0: resolution: {integrity: sha512-41Fs7Q/PLq1SDbqjsgcY7GA42T0jvaCNGXgGtsNdvg+Yv8eIu06bxv4/PoREkZ9nMDNwnUSG9OFB9+yv8eKhDg==} @@ -2486,6 +2493,8 @@ snapshots: dependencies: esutils: 2.0.3 + dotenv@16.4.5: {} + earcut@3.0.0: {} eastasianwidth@0.2.0: {} diff --git a/svelte.config.js b/svelte.config.js index 152e7a0..0bd1241 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,12 +1,20 @@ import adapter from '@sveltejs/adapter-node'; +import dotenv from 'dotenv'; + +// 加载环境变量 +dotenv.config(); + /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. // If your environment is not supported or you settled on a specific environment, switch out the adapter. // See https://kit.svelte.dev/docs/adapters for more information about adapters. - adapter: adapter() + adapter: adapter(), + paths: { + base: process.env.VITE_BASE || '/hospital', + } } }; diff --git a/vite.config.js b/vite.config.js index 92674d8..0a414a9 100644 --- a/vite.config.js +++ b/vite.config.js @@ -3,10 +3,9 @@ import { defineConfig, loadEnv } from 'vite'; export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd()); - const { VITE_BASE, VITE_JSCODE } = env; + const { VITE_JSCODE } = env; return { - base: VITE_BASE || '/', plugins: [sveltekit()], server: { proxy: {