Commit fb92a330 authored by 前端-许佳敏's avatar 前端-许佳敏

chore: 优化构建流程

parent d4acc3f2
......@@ -10,9 +10,6 @@ import proxy from './proxy'
import CaseSensitivePathsWebpackPlugins from 'case-sensitive-paths-webpack-plugin'
import theme from './theme.config'
if (!process.env.SITE_ID || !process.env.BACK_GATEWAY || !process.env.SOCKET_URL) {
throw `请检查环境变量是否传入, ${process.env.PRO_ENV}`
}
export default defineConfig({
title: '瓴犀平台后台',
// 如需写入环境变量 需在config中先写入
......
......@@ -13,8 +13,9 @@
"api": "god-ytt",
"start:analyze": "ANALYZE=1 umi dev",
"scripts:build": "node scripts/run",
"scripts:init": "node scripts/init",
"scripts:build-yxc": "node scripts/run http://yxc-web-demo.shushangyun.com/api",
"start": "yarn api && yarn scripts:build && umi dev",
"start": "yarn scripts:init && yarn api && yarn scripts:build && umi dev",
"start:dev": "umi dev",
"build": "yarn api && yarn scripts:build && yarn build:clean",
"build:yxc": "yarn api && yarn scripts:build-yxc && umi build",
......
const path = require('path')
const envValue = require('../env')
const { setEnv } = require('./utils/envTool')
/**
* 初始化脚本
*/
function validateEnvParams() {
const validateErrorsMaps = {
SITE_ID: `请检查站点ID是否传入,--- ${process.env.SITE_ID} ---`,
BACK_GATEWAY: `请检查后端网关是否传入, --- ${process.env.BACK_GATEWAY} ---`,
SOCKET_URL: `请检查socket链接是否传入, --- ${process.env.SOCKET_URL} ---`,
YAPI_URL: `请检查yapi的请求连接是否传入, --- ${process.env.YAPI_URL} ---`,
}
Object.keys(validateErrorsMaps).map(key => {
if (!process.env[key]) {
throw validateErrorsMaps[key]
}
})
}
// 将env.js的内容注入到 项目中
function injectEnvParams() {
const { PRO_ENV } = process.env
if (!PRO_ENV) {
throw `请传入PRO_ENV作为环境变量`
}
const envMaps = envValue[PRO_ENV]
setEnv(envMaps)
}
function init() {
injectEnvParams()
// 校验参数是否都成功传入
validateEnvParams()
}
init()
const gulp = require('gulp')
const envValue = require('../env')
const { setEnv, getEnv } = require('./utils/envTool')
const taskName = process.env.taskName || 'start'
// 本地构建时带上的环境变量
const PRO_ENV = process.env.PRO_ENV
if (PRO_ENV) {
process.env.SITE_ID = envValue[PRO_ENV].SITE_ID
process.env.BACK_GATEWAY = envValue[PRO_ENV].BACK_GATEWAY
process.env.USE_ROUTE_CONFIG = envValue[PRO_ENV].USE_ROUTE_CONFIG
process.env.SOCKET_URL = envValue[PRO_ENV].SOCKET_URL
process.env.ssh = envValue[PRO_ENV].ssh
if (!PRO_ENV) {
throw `请传入PRO_ENV`
}
setEnv(getEnv(envValue))
function runTask(toRun) {
const metadata = { task: toRun };
......
function getEnv(envConfig) {
if (!envConfig) {
throw `检查是否传入PRO_ENV`
}
return envConfig[process.env.PRO_ENV]
}
function setEnv(envs) {
Object.keys(envs).forEach(key => {
process.env[key] = envs[key]
})
}
module.exports = {
getEnv,
setEnv,
}
const YAPI_URL = require('./env.js')[process.env.PRO_ENV]
process.env.YAPI_URL = require('./env')[process.env.PRO_ENV].YAPI_URL
if (!YAPI_URL) {
if (!process.env.YAPI_URL) {
throw 'yapi链接不存在'
}
......@@ -24,7 +24,7 @@ const tokenList = [
]
const getConfigMap = (tokens) => tokens.map(v => ({
serverUrl: YAPI_URL,
serverUrl: process.env.YAPI_URL,
typesOnly: false,
reactHooks: {
enabled: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment