Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
feat: 支持通过 --port 指定端口号
Browse files Browse the repository at this point in the history
  • Loading branch information
inJs authored and yesmeck committed May 20, 2020
1 parent e2ce763 commit fb2a78f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/remax-cli/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Argv {
target: Platform;
watch?: boolean;
notify?: boolean;
port?: number;
}

export function run(options: Options): webpack.Compiler {
Expand Down
8 changes: 7 additions & 1 deletion packages/remax-cli/src/build/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ export default function buildWeb(api: API, options: Options): webpack.Compiler {
const compiler = webpack(webpackOptions);

if (options.watch) {
detect(3000, (err, port) => {
const designatedPort = options.port ?? 3000;

detect(designatedPort, (err, port) => {
if (err) {
output.error(err.message);

return;
}

if (designatedPort !== port) {
output.warn(`端口: ${designatedPort} 被占用,系统已分配另一个可用端口:${port}`);
}

output.message('🚀 启动 watch', 'blue');
output.message(`📎 http:https://localhost:${port}`, 'blue');
output.message(`📎 http:https://${address.ip()}:${port}\n`, 'blue');
Expand Down
1 change: 1 addition & 0 deletions packages/remax-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Options {
notify?: boolean;
watch?: boolean;
target?: Platform;
port?: number;
}

export type Config = Partial<Options>;
Expand Down

0 comments on commit fb2a78f

Please sign in to comment.