From b7ce7912a7bae1b57639762f435dd219980cbbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Sat, 25 Jun 2022 14:45:23 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E7=AE=80=E5=8C=96=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4=EF=BC=8C=E6=92=A4=E9=94=80app.config.js?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 ++-- .env.github | 4 ++-- .env.production | 4 ++-- .env.test | 4 ++-- build/constant.js | 2 -- build/plugin/html.js | 17 ----------------- build/script/build-cname.js | 6 +++--- build/script/build-config.js | 29 ----------------------------- build/script/index.js | 2 -- build/utils.js | 4 ++-- package.json | 6 +++--- src/utils/http/index.js | 4 ++-- 12 files changed, 18 insertions(+), 68 deletions(-) delete mode 100644 build/script/build-config.js diff --git a/.env.development b/.env.development index 2f5b04c..dbf6f6b 100644 --- a/.env.development +++ b/.env.development @@ -8,7 +8,7 @@ VITE_APP_USE_MOCK = true VITE_PROXY = [["/api","http://localhost:8080"],["/api-test","localhost:8080"]] # base api -VITE_APP_GLOB_BASE_API = '/api' +VITE_APP_BASE_API = '/api' # test base api -VITE_APP_GLOB_BASE_API_TEST = '/api-test' \ No newline at end of file +VITE_APP_BASE_API_TEST = '/api-test' \ No newline at end of file diff --git a/.env.github b/.env.github index 953a4fc..b901816 100644 --- a/.env.github +++ b/.env.github @@ -10,7 +10,7 @@ VITE_APP_USE_HASH = true VITE_APP_USE_MOCK = true # base api -VITE_APP_GLOB_BASE_API = '/api' +VITE_APP_BASE_API = '/api' # test base api -VITE_APP_GLOB_BASE_API_TEST = '/api-test' \ No newline at end of file +VITE_APP_BASE_API_TEST = '/api-test' \ No newline at end of file diff --git a/.env.production b/.env.production index d046738..92abf61 100644 --- a/.env.production +++ b/.env.production @@ -5,7 +5,7 @@ VITE_PUBLIC_PATH = '/' VITE_APP_USE_MOCK = true # base api -VITE_APP_GLOB_BASE_API = '/api' +VITE_APP_BASE_API = '/api' # test base api -VITE_APP_GLOB_BASE_API_TEST = '/api-test' \ No newline at end of file +VITE_APP_BASE_API_TEST = '/api-test' \ No newline at end of file diff --git a/.env.test b/.env.test index 847db2b..95d6ea1 100644 --- a/.env.test +++ b/.env.test @@ -4,7 +4,7 @@ VITE_PUBLIC_PATH = '/' VITE_APP_USE_MOCK = true # base api -VITE_APP_GLOB_BASE_API = '/api' +VITE_APP_BASE_API = '/api' # test base api -VITE_APP_GLOB_BASE_API_TEST = '/api-test' \ No newline at end of file +VITE_APP_BASE_API_TEST = '/api-test' \ No newline at end of file diff --git a/build/constant.js b/build/constant.js index d8c4f4b..cdf559a 100644 --- a/build/constant.js +++ b/build/constant.js @@ -1,3 +1 @@ -export const GLOB_CONFIG_FILE_NAME = 'app.config.js' -export const GLOB_CONFIG_NAME = '__APP__GLOB__CONF__' export const OUTPUT_DIR = 'dist' diff --git a/build/plugin/html.js b/build/plugin/html.js index 5a62a99..8e3ebc4 100644 --- a/build/plugin/html.js +++ b/build/plugin/html.js @@ -1,14 +1,7 @@ import { createHtmlPlugin } from 'vite-plugin-html' -import { version } from '../../package.json' -import { GLOB_CONFIG_FILE_NAME } from '../constant' export function configHtmlPlugin(viteEnv, isBuild) { const { VITE_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv - const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/` - - const getAppConfigSrc = () => { - return `${path}${GLOB_CONFIG_FILE_NAME}?v=${version}-${new Date().getTime()}` - } const htmlPlugin = createHtmlPlugin({ minify: isBuild, @@ -16,16 +9,6 @@ export function configHtmlPlugin(viteEnv, isBuild) { data: { title: VITE_APP_TITLE, }, - tags: isBuild - ? [ - { - tag: 'script', - attrs: { - src: getAppConfigSrc(), - }, - }, - ] - : [], }, }) return htmlPlugin diff --git a/build/script/build-cname.js b/build/script/build-cname.js index dbcbc2e..f8421ab 100644 --- a/build/script/build-cname.js +++ b/build/script/build-cname.js @@ -4,10 +4,10 @@ import { OUTPUT_DIR } from '../constant' import { getEnvConfig, getRootPath } from '../utils' export function runBuildCNAME() { - const { VITE_APP_GLOB_CNAME } = getEnvConfig() - if (!VITE_APP_GLOB_CNAME) return + const { VITE_APP_CNAME } = getEnvConfig() + if (!VITE_APP_CNAME) return try { - writeFileSync(getRootPath(`${OUTPUT_DIR}/CNAME`), VITE_APP_GLOB_CNAME) + writeFileSync(getRootPath(`${OUTPUT_DIR}/CNAME`), VITE_APP_CNAME) } catch (error) { console.log(chalk.red('CNAME file failed to package:\n' + error)) } diff --git a/build/script/build-config.js b/build/script/build-config.js deleted file mode 100644 index 94f7ede..0000000 --- a/build/script/build-config.js +++ /dev/null @@ -1,29 +0,0 @@ -import { GLOB_CONFIG_FILE_NAME, GLOB_CONFIG_NAME, OUTPUT_DIR } from '../constant' -import fs, { writeFileSync } from 'fs-extra' -import chalk from 'chalk' -import { getEnvConfig, getRootPath } from '../utils' - -function createConfig(option) { - const { config, configName, configFileName } = option - try { - const windowConf = `window.${configName}` - const configStr = `${windowConf}=${JSON.stringify(config)}; - Object.freeze(${windowConf}); - Object.defineProperty(window, "${configName}", { - configurable: false, - writable: false, - }); - `.replace(/\s/g, '') - fs.mkdirp(getRootPath(OUTPUT_DIR)) - writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr) - } catch (error) { - console.log(chalk.red('configuration file configuration file failed to package:\n' + error)) - } -} - -export function runBuildConfig() { - const config = getEnvConfig() - const configName = GLOB_CONFIG_NAME - const configFileName = GLOB_CONFIG_FILE_NAME - createConfig({ config, configName, configFileName }) -} diff --git a/build/script/index.js b/build/script/index.js index c208e25..e0efeb0 100644 --- a/build/script/index.js +++ b/build/script/index.js @@ -1,10 +1,8 @@ import chalk from 'chalk' -import { runBuildConfig } from './build-config' import { runBuildCNAME } from './build-cname' export const runBuild = async () => { try { - runBuildConfig() runBuildCNAME() console.log(`✨ ${chalk.cyan('build successfully!')}`) } catch (error) { diff --git a/build/utils.js b/build/utils.js index 24cd764..d5b6315 100644 --- a/build/utils.js +++ b/build/utils.js @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import dotenv from 'dotenv' -const httpsRE = /^https:\/\// +const httpsReg = /^https:\/\// export function wrapperEnv(envOptions) { if (!envOptions) return {} @@ -36,7 +36,7 @@ export function wrapperEnv(envOptions) { export function createProxy(list = []) { const ret = {} for (const [prefix, target] of list) { - const isHttps = httpsRE.test(target) + const isHttps = httpsReg.test(target) // https://github.com/http-party/node-http-proxy#options ret[prefix] = { diff --git a/package.json b/package.json index 2f67e13..7ef42ff 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "vue-naive-admin", - "version": "0.3.2", + "version": "0.4.0", "scripts": { "dev": "vite", "lint": "eslint --ext .js,.vue .", "lint:fix": "eslint --fix --ext .js,.vue .", - "build": "vite build && esno ./build/script", - "build:test": "vite build --mode test && esno ./build/script", + "build": "vite build", + "build:test": "vite build --mode test", "build:github": "vite build --mode github && esno ./build/script", "preview": "vite preview" }, diff --git a/src/utils/http/index.js b/src/utils/http/index.js index 089cb49..6c9d12b 100644 --- a/src/utils/http/index.js +++ b/src/utils/http/index.js @@ -3,7 +3,7 @@ import { repReject, repResolve, reqReject, reqResolve } from './interceptors' export function createAxios(options = {}) { const defaultOptions = { - baseURL: window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API || import.meta.env.VITE_APP_GLOB_BASE_API, + baseURL: import.meta.env.VITE_APP_BASE_API, timeout: 12000, } const service = axios.create({ @@ -18,5 +18,5 @@ export function createAxios(options = {}) { export const defAxios = createAxios() export const testAxios = createAxios({ - baseURL: window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API_TEST || import.meta.env.VITE_APP_GLOB_BASE_API_TEST, + baseURL: import.meta.env.VITE_APP_BASE_API_TEST, })