refactor: 简化文件夹结构
This commit is contained in:
parent
c268b3c75d
commit
d8569a4eb1
@ -1,6 +1,6 @@
|
|||||||
import html from 'vite-plugin-html'
|
import html from 'vite-plugin-html'
|
||||||
import { version } from '../../../package.json'
|
import { version } from '../../package.json'
|
||||||
import { GLOB_CONFIG_FILE_NAME } from '../../constant'
|
import { GLOB_CONFIG_FILE_NAME } from '../constant'
|
||||||
|
|
||||||
export function configHtmlPlugin(viteEnv, isBuild) {
|
export function configHtmlPlugin(viteEnv, isBuild) {
|
||||||
const { VITE_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv
|
const { VITE_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv
|
@ -2,6 +2,8 @@ import fs from 'fs'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
|
||||||
|
const httpsRE = /^https:\/\//
|
||||||
|
|
||||||
export function wrapperEnv(envOptions) {
|
export function wrapperEnv(envOptions) {
|
||||||
if (!envOptions) return {}
|
if (!envOptions) return {}
|
||||||
const ret = {}
|
const ret = {}
|
||||||
@ -31,6 +33,24 @@ export function wrapperEnv(envOptions) {
|
|||||||
return ret
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前环境下生效的配置文件名
|
* 获取当前环境下生效的配置文件名
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -1,9 +1,8 @@
|
|||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
import { wrapperEnv } from './build/utils'
|
import { wrapperEnv, createProxy } from './build/utils'
|
||||||
import { createVitePlugins } from './build/vite/plugin'
|
import { createVitePlugins } from './build/plugin'
|
||||||
import { createProxy } from './build/vite/proxy'
|
|
||||||
import { OUTPUT_DIR } from './build/constant'
|
import { OUTPUT_DIR } from './build/constant'
|
||||||
|
|
||||||
export default defineConfig(({ command, mode }) => {
|
export default defineConfig(({ command, mode }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user