Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ $ build-scripts start --help
Usage: build-scripts start [options]

Options:
--port <port> 服务端口号
--host <host> 服务主机名
--config <config> 自定义配置文件路径(支持 json 或者 js,推荐命名 build.config.js/build.json)
--port <port> 服务端口号
--host <host> 服务主机名
--config <config> 自定义配置文件路径(支持 json 或者 js,推荐命名 build.config.js/build.json)
```

build 命令:
Expand All @@ -51,7 +51,7 @@ $ build-scripts build --help
Usage: build-scripts build [options]

Options:
--config <config> 同 start
--config <config> 同 start
```

test 命令:
Expand Down Expand Up @@ -337,6 +337,21 @@ module.exports = ({ registerUserConfig }) => {
};
```

#### hasRegistration

判断 build.json 中的顶层配置字段或者 cli 参数是否已经注册:

```js
module.exports = ({ hasRegistration }) => {
// 判断 build.json 顶层配置字段 entry 是否已配置
const hasEntryRegistered = hasRegistration('entry');

// 判断 cli --https 参数是否已被注册
const hasHttpsRegistered = hasRegistration('https', 'cliOption');
...
}
```

#### modifyConfigRegistration

用于修改已注册用户配置的行为:
Expand Down
1 change: 1 addition & 0 deletions packages/build-scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [feat] support deep merge of modifyUserConfig by options
- [feat] enhance registerMethod API, make it possible to get plugin name when applyMethod
- [feat] add `originalUserConfig` to plugin API
- [feat] support `hasRegistration` api
- [fix] move webpack-dev-server to peerDependencies and migrate webpack-dev-server to 4.0.0

## 1.0.1
Expand Down
6 changes: 6 additions & 0 deletions packages/build-scripts/src/core/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@ class Context {
this.registerConfig('userConfig', args);
};

public hasRegistration = (name: string, type: 'cliOption' | 'userConfig' = 'userConfig' ): boolean => {
const mappedType = type === 'cliOption' ? 'cliOptionRegistration' : 'userConfigRegistration';
return Object.keys(this[mappedType] || {}).includes(name);
};

public registerCliOption = (args: MaybeArray<ICliOptionArgs>): void => {
this.registerConfig('cliOption', args, name => {
return camelCase(name, { pascalCase: false });
Expand Down Expand Up @@ -766,6 +771,7 @@ class Context {
setValue: this.setValue,
getValue: this.getValue,
registerUserConfig: this.registerUserConfig,
hasRegistration: this.hasRegistration,
registerCliOption: this.registerCliOption,
registerMethod: this.registerMethod,
applyMethod,
Expand Down