Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-admin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈智峰
jinfa-admin
Commits
fb92a330
Commit
fb92a330
authored
Nov 18, 2021
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 优化构建流程
parent
d4acc3f2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
69 additions
and
13 deletions
+69
-13
config.ts
config/config.ts
+0
-3
package.json
package.json
+2
-1
init.js
scripts/init.js
+43
-0
run.js
scripts/run.js
+4
-6
envTool.js
scripts/utils/envTool.js
+17
-0
ytt.config.ts
ytt.config.ts
+3
-3
No files found.
config/config.ts
View file @
fb92a330
...
...
@@ -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中先写入
...
...
package.json
View file @
fb92a330
...
...
@@ -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"
,
...
...
scripts/init.js
0 → 100644
View file @
fb92a330
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
()
scripts/run.js
View file @
fb92a330
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
};
...
...
scripts/utils/envTool.js
0 → 100644
View file @
fb92a330
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
,
}
ytt.config.ts
View file @
fb92a330
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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment