@@ -2,14 +2,15 @@ import type { RsbuildMode } from '@rsbuild/core';
22import { type Command , program } from 'commander' ;
33import { logger } from '../utils/logger' ;
44import { build } from './build' ;
5- import { loadRslibConfig } from './init' ;
5+ import { init } from './init' ;
66import { inspect } from './inspect' ;
77import { startMFDevServer } from './mf' ;
88import { watchFilesForRestart } from './restart' ;
99
1010export type CommonOptions = {
1111 root ?: string ;
1212 config ?: string ;
13+ envDir ?: string ;
1314 envMode ?: string ;
1415 lib ?: string [ ] ;
1516} ;
@@ -37,7 +38,8 @@ const applyCommonOptions = (command: Command) => {
3738 . option (
3839 '--env-mode <mode>' ,
3940 'specify the env mode to load the `.env.[mode]` file' ,
40- ) ;
41+ )
42+ . option ( '--env-dir <dir>' , 'specify the directory to load `.env` files' ) ;
4143} ;
4244
4345const repeatableOption = ( value : string , previous : string [ ] ) => {
@@ -64,13 +66,12 @@ export function runCli(): void {
6466 . action ( async ( options : BuildOptions ) => {
6567 try {
6668 const cliBuild = async ( ) => {
67- const { content : rslibConfig , filePath } =
68- await loadRslibConfig ( options ) ;
69+ const { config, watchFiles } = await init ( options ) ;
6970
70- await build ( rslibConfig , options ) ;
71+ await build ( config , options ) ;
7172
7273 if ( options . watch ) {
73- watchFilesForRestart ( [ filePath ] , async ( ) => {
74+ watchFilesForRestart ( watchFiles , async ( ) => {
7475 await cliBuild ( ) ;
7576 } ) ;
7677 }
@@ -100,8 +101,8 @@ export function runCli(): void {
100101 . action ( async ( options : InspectOptions ) => {
101102 try {
102103 // TODO: inspect should output Rslib's config
103- const { content : rslibConfig } = await loadRslibConfig ( options ) ;
104- await inspect ( rslibConfig , {
104+ const { config } = await init ( options ) ;
105+ await inspect ( config , {
105106 lib : options . lib ,
106107 mode : options . mode ,
107108 output : options . output ,
@@ -119,12 +120,11 @@ export function runCli(): void {
119120 . action ( async ( options : CommonOptions ) => {
120121 try {
121122 const cliMfDev = async ( ) => {
122- const { content : rslibConfig , filePath } =
123- await loadRslibConfig ( options ) ;
123+ const { config, watchFiles } = await init ( options ) ;
124124 // TODO: support lib option in mf dev server
125- await startMFDevServer ( rslibConfig ) ;
125+ await startMFDevServer ( config ) ;
126126
127- watchFilesForRestart ( [ filePath ] , async ( ) => {
127+ watchFilesForRestart ( watchFiles , async ( ) => {
128128 await cliMfDev ( ) ;
129129 } ) ;
130130 } ;
0 commit comments