-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement(ddn-core): configured according to different environments
BREAKING CHANGE: 可以通过环境变量 `DDN_ENV` 区分不同环境来指定配置
- Loading branch information
Showing
24 changed files
with
354 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Contribute | ||
|
||
## Set up | ||
|
||
Clone the repo. | ||
|
||
```bash | ||
$ git clone https://github.com/ddnlink/ddn.git | ||
``` | ||
|
||
Install dev deps after git clone the repo. | ||
|
||
```bash | ||
$ cd ddn | ||
$ yarn | ||
``` | ||
|
||
Bootstrap every package with yarn. (Need to execute when new package is included) | ||
|
||
```bash | ||
$ yarn bootstrap | ||
``` | ||
|
||
Build first. | ||
|
||
```bash | ||
$ yarn build | ||
``` | ||
|
||
Run it. | ||
|
||
```bash | ||
$ yarn start | ||
``` | ||
|
||
## Common Tasks | ||
|
||
Monitor file changes and transform with babel. | ||
|
||
```bash | ||
$ yarn build --watch | ||
``` | ||
|
||
Run test. | ||
|
||
```bash | ||
# Including e2e test | ||
$ yarn test | ||
|
||
# Unit test only | ||
$ yarn test .test.(t|j)s | ||
|
||
# Test specified file and watch | ||
$ yarn test getMockData.test.js -w | ||
|
||
# Test specified package | ||
$ PACKAGE=ddn-core yarn test | ||
|
||
# Don't run e2e test | ||
$ E2E=none yarn test | ||
|
||
# Generate coverage | ||
$ yarn test --coverage | ||
``` | ||
|
||
Publish to npm. | ||
|
||
```bash | ||
# Generator the changelog first. | ||
$ yarn changelog | ||
|
||
# Do not use yarn for this command. | ||
$ npm run publish | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# 配置 | ||
|
||
## 配置文件 | ||
|
||
DDN 允许在 `.ddnrc.js` ,`config/config.json` 或 `config/config.js`(三选一,`.ddnrc.js` 优先)中进行配置,支持 ES6 语法。 | ||
|
||
> 为简化说明,后续文档里只会出现 `.ddnrc.js`。 | ||
比如: | ||
|
||
```js | ||
export default { | ||
base: '/admin/', | ||
publicPath: 'http://cdn.com/foo', | ||
plugins: [ | ||
['umi-plugin-react', { | ||
dva: true, | ||
}], | ||
], | ||
}; | ||
``` | ||
|
||
具体配置项详见[配置](/zh/config/)。 | ||
|
||
## .ddnrc.local.js | ||
|
||
`.ddnrc.local.js` 是本地的配置文件,**不要提交到 git**,所以通常需要配置到 `.gitignore`。如果存在,会和 `.ddnrc.js` 合并后再返回。 | ||
|
||
## DDN_ENV | ||
|
||
可以通过环境变量 `DDN_ENV` 区分不同环境来指定配置。 | ||
|
||
举个例子, | ||
|
||
```js | ||
// .ddnrc.js | ||
export default { a: 1, b: 2 }; | ||
|
||
// .ddnrc.cloud.js | ||
export default { b: 'cloud', c: 'cloud' }; | ||
|
||
// .ddnrc.local.js | ||
export default { c: 'local' }; | ||
``` | ||
|
||
不指定 `DDN_ENV` 时,拿到的配置是: | ||
|
||
```js | ||
{ | ||
a: 1, | ||
b: 2, | ||
c: 'local', | ||
} | ||
``` | ||
|
||
指定 `DDN_ENV=cloud` 时,拿到的配置是: | ||
|
||
```js | ||
{ | ||
a: 1, | ||
b: 'cloud', | ||
c: 'local', | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
sidebarDepth: 2 | ||
--- | ||
|
||
# 配置 | ||
|
||
## 基本配置 | ||
|
||
### 资产插件 | ||
|
||
- 类型:`Array` | ||
- 默认值:`[]` | ||
|
||
配置插件列表。 | ||
|
||
数组项为指向插件的路径,可以是 npm 依赖、相对路径或绝对路径。如果是相对路径,则会从项目根目录开始找。比如: | ||
|
||
```js | ||
export default { | ||
plugins: [ | ||
// npm 依赖 | ||
'ddn-aob', | ||
// 相对路径 | ||
'./plugin', | ||
// 绝对路径 | ||
`${__dirname}/plugin.js`, | ||
], | ||
}; | ||
``` | ||
|
||
如果插件有参数,则通过数组的形式进行配置,第一项是路径,第二项是参数,类似 babel 插件的配置方式。比如: | ||
|
||
```js | ||
export default { | ||
plugins: [ | ||
// 有参数 | ||
[ | ||
'ddn-aob', | ||
{ | ||
a: true, | ||
b: true, | ||
}, | ||
], | ||
'./plugin', | ||
], | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/ddn-core/test/fixtures/getUserConfig/config-configjson/config/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"history": "hash" | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/ddn-core/test/fixtures/getUserConfig/config-configjson/config/config.local.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
export default { | ||
history: 'local', | ||
story: 'ok' | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/ddn-core/test/fixtures/getUserConfig/config-ddnrc/.ddnrc.local.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export default { | ||
history: 'sorry', | ||
story: 'ok', | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
packages/ddn-core/test/fixtures/getUserConfig/config-ddnrc/.ddnrc.prod.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export default { | ||
history: 'prod', | ||
story: 'yes', | ||
} | ||
|
4 changes: 4 additions & 0 deletions
4
packages/ddn-core/test/fixtures/getUserConfig/requireFile/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"a": 1, | ||
"b": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
"port": 8000 | ||
} |
Oops, something went wrong.