From d8569a4eb1a921b447180256684bb5a07bcc003e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Tue, 3 May 2022 22:37:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=AE=80=E5=8C=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/{vite => }/plugin/html.js | 4 ++-- build/{vite => }/plugin/index.js | 0 build/{vite => }/plugin/mock.js | 0 build/{vite => }/plugin/unocss.js | 0 build/utils.js | 20 ++++++++++++++++++++ build/vite/proxy.js | 18 ------------------ vite.config.js | 5 ++--- 7 files changed, 24 insertions(+), 23 deletions(-) rename build/{vite => }/plugin/html.js (87%) rename build/{vite => }/plugin/index.js (100%) rename build/{vite => }/plugin/mock.js (100%) rename build/{vite => }/plugin/unocss.js (100%) delete mode 100644 build/vite/proxy.js diff --git a/build/vite/plugin/html.js b/build/plugin/html.js similarity index 87% rename from build/vite/plugin/html.js rename to build/plugin/html.js index 1502d87..471f3ab 100644 --- a/build/vite/plugin/html.js +++ b/build/plugin/html.js @@ -1,6 +1,6 @@ import html from 'vite-plugin-html' -import { version } from '../../../package.json' -import { GLOB_CONFIG_FILE_NAME } from '../../constant' +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 diff --git a/build/vite/plugin/index.js b/build/plugin/index.js similarity index 100% rename from build/vite/plugin/index.js rename to build/plugin/index.js diff --git a/build/vite/plugin/mock.js b/build/plugin/mock.js similarity index 100% rename from build/vite/plugin/mock.js rename to build/plugin/mock.js diff --git a/build/vite/plugin/unocss.js b/build/plugin/unocss.js similarity index 100% rename from build/vite/plugin/unocss.js rename to build/plugin/unocss.js diff --git a/build/utils.js b/build/utils.js index 178e594..81765f6 100644 --- a/build/utils.js +++ b/build/utils.js @@ -2,6 +2,8 @@ import fs from 'fs' import path from 'path' import dotenv from 'dotenv' +const httpsRE = /^https:\/\// + export function wrapperEnv(envOptions) { if (!envOptions) return {} const ret = {} @@ -31,6 +33,24 @@ export function wrapperEnv(envOptions) { return ret } +export function createProxy(list = []) { + const ret = {} + for (const [prefix, target] of list) { + const isHttps = httpsRE.test(target) + + // https://github.com/http-party/node-http-proxy#options + ret[prefix] = { + target: target, + changeOrigin: true, + ws: true, + rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''), + // https is require secure=false + ...(isHttps ? { secure: false } : {}), + } + } + return ret +} + /** * 获取当前环境下生效的配置文件名 */ diff --git a/build/vite/proxy.js b/build/vite/proxy.js deleted file mode 100644 index 74cc5a7..0000000 --- a/build/vite/proxy.js +++ /dev/null @@ -1,18 +0,0 @@ -const httpsRE = /^https:\/\// -export function createProxy(list = []) { - const ret = {} - for (const [prefix, target] of list) { - const isHttps = httpsRE.test(target) - - // https://github.com/http-party/node-http-proxy#options - ret[prefix] = { - target: target, - changeOrigin: true, - ws: true, - rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''), - // https is require secure=false - ...(isHttps ? { secure: false } : {}), - } - } - return ret -} diff --git a/vite.config.js b/vite.config.js index e1222d3..8ee6eb1 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,9 +1,8 @@ import { defineConfig, loadEnv } from 'vite' import path from 'path' -import { wrapperEnv } from './build/utils' -import { createVitePlugins } from './build/vite/plugin' -import { createProxy } from './build/vite/proxy' +import { wrapperEnv, createProxy } from './build/utils' +import { createVitePlugins } from './build/plugin' import { OUTPUT_DIR } from './build/constant' export default defineConfig(({ command, mode }) => {