环境变量

dev
LiuJiaNan 2024-04-12 10:26:05 +08:00
parent f77aa17083
commit f2e8d02867
6 changed files with 41 additions and 15 deletions

View File

@ -2,4 +2,4 @@ public
dist dist
package.json package.json
!.prettierrc.cjs !.prettierrc.cjs
src/vite-env.d.ts env.d.ts

27
env.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
interface ImportMetaEnv {
// Auto generate by env-parse
/**
* undefined
*/
readonly VITE_BASE_URL: string
/**
* undefined
*/
readonly VITE_PROXY: Record<string, any>
/**
* undefined
*/
readonly VITE_FILE_URL: string
/**
* undefined
*/
readonly VITE_TEMPLATE_URL: string
/**
* undefined
*/
readonly VITE_ON_LINE_WEB_SOCKET_URL: string
/**
* undefined
*/
readonly VITE_LEARNING_WEB_SOCKET_URL: string
}

10
package-lock.json generated
View File

@ -68,6 +68,7 @@
"unplugin-vue-components": "^0.22.12", "unplugin-vue-components": "^0.22.12",
"vite": "^4.5.1", "vite": "^4.5.1",
"vite-plugin-enhance-log": "^0.5.2", "vite-plugin-enhance-log": "^0.5.2",
"vite-plugin-env-parse": "^1.0.10",
"vite-plugin-eslint": "^1.8.1", "vite-plugin-eslint": "^1.8.1",
"vite-plugin-remove-console": "^2.2.0", "vite-plugin-remove-console": "^2.2.0",
"vue-eslint-parser": "^9.3.2" "vue-eslint-parser": "^9.3.2"
@ -5966,6 +5967,15 @@
"vite": "^2.9.0 || ^3.0.0 || ^4.0.0" "vite": "^2.9.0 || ^3.0.0 || ^4.0.0"
} }
}, },
"node_modules/vite-plugin-env-parse": {
"version": "1.0.10",
"resolved": "https://registry.npmmirror.com/vite-plugin-env-parse/-/vite-plugin-env-parse-1.0.10.tgz",
"integrity": "sha512-7C3ixNz02ExrYCZRkAhXRWXqWktR/YO/SkrCdOUFR3GCXALUGt4xNhTTVZonKH8SpA4xe1wp2mS606MKZdvOpw==",
"dev": true,
"peerDependencies": {
"vite": "*"
}
},
"node_modules/vite-plugin-eslint": { "node_modules/vite-plugin-eslint": {
"version": "1.8.1", "version": "1.8.1",
"resolved": "https://registry.npmmirror.com/vite-plugin-eslint/-/vite-plugin-eslint-1.8.1.tgz", "resolved": "https://registry.npmmirror.com/vite-plugin-eslint/-/vite-plugin-eslint-1.8.1.tgz",

View File

@ -70,6 +70,7 @@
"unplugin-vue-components": "^0.22.12", "unplugin-vue-components": "^0.22.12",
"vite": "^4.5.1", "vite": "^4.5.1",
"vite-plugin-enhance-log": "^0.5.2", "vite-plugin-enhance-log": "^0.5.2",
"vite-plugin-env-parse": "^1.0.10",
"vite-plugin-eslint": "^1.8.1", "vite-plugin-eslint": "^1.8.1",
"vite-plugin-remove-console": "^2.2.0", "vite-plugin-remove-console": "^2.2.0",
"vue-eslint-parser": "^9.3.2" "vue-eslint-parser": "^9.3.2"

14
src/vite-env.d.ts vendored
View File

@ -1,14 +0,0 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_BASE_URL: string
readonly VITE_PROXY: string
readonly VITE_FILE_URL: string
readonly VITE_TEMPLATE_URL: string
readonly VITE_ON_LINE_WEB_SOCKET_URL: string
readonly VITE_LEARNING_WEB_SOCKET_URL: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}

View File

@ -10,11 +10,13 @@ import {
// import basicSsl from "@vitejs/plugin-basic-ssl"; // import basicSsl from "@vitejs/plugin-basic-ssl";
import removeConsole from "vite-plugin-remove-console"; import removeConsole from "vite-plugin-remove-console";
import EnhanceLog from "vite-plugin-enhance-log"; import EnhanceLog from "vite-plugin-enhance-log";
import { envParse } from "vite-plugin-env-parse";
export default ({ mode }) => { export default ({ mode }) => {
return defineConfig({ return defineConfig({
plugins: [ plugins: [
vue(), vue(),
envParse(),
eslintPlugin(), eslintPlugin(),
removeConsole({ removeConsole({
includes: [ includes: [