revert: 简化构建步骤,撤销app.config.js功能
This commit is contained in:
parent
1fa9d4d472
commit
b7ce7912a7
@ -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'
|
||||
VITE_APP_BASE_API_TEST = '/api-test'
|
@ -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'
|
||||
VITE_APP_BASE_API_TEST = '/api-test'
|
@ -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'
|
||||
VITE_APP_BASE_API_TEST = '/api-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'
|
||||
VITE_APP_BASE_API_TEST = '/api-test'
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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 })
|
||||
}
|
@ -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) {
|
||||
|
@ -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] = {
|
||||
|
@ -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"
|
||||
},
|
||||
|
@ -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,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user