@@ -10,6 +10,7 @@ export type pluginDtsOptions = {
1010} ;
1111
1212export type DtsGenOptions = {
13+ name : string ;
1314 options : pluginDtsOptions ;
1415 cwd : string ;
1516 isWatch : boolean ;
@@ -34,34 +35,49 @@ export const pluginDts = (options: pluginDtsOptions): RsbuildPlugin => ({
3435
3536 const dtsPromises : Promise < void > [ ] = [ ] ;
3637
37- api . onBeforeBuild ( ( { isWatch } ) => {
38- const jsExtension = extname ( __filename ) ;
39- const childProcess = fork ( join ( __dirname , `./dts ${ jsExtension } ` ) , [ ] , {
40- stdio : 'inherit' ,
41- } ) ;
38+ api . onBeforeEnvironmentCompile (
39+ ( { isWatch , isFirstCompile , environment } ) => {
40+ if ( ! isFirstCompile ) {
41+ return ;
42+ }
4243
43- const dtsGenOptions = {
44- options,
45- cwd : api . context . rootPath ,
46- isWatch,
47- } ;
44+ const jsExtension = extname ( __filename ) ;
45+ const childProcess = fork ( join ( __dirname , `./dts${ jsExtension } ` ) , [ ] , {
46+ stdio : 'inherit' ,
47+ } ) ;
4848
49- childProcess . send ( dtsGenOptions ) ;
49+ const dtsGenOptions = {
50+ name : environment . name ,
51+ options,
52+ cwd : api . context . rootPath ,
53+ isWatch,
54+ } ;
5055
51- dtsPromises . push (
52- new Promise ( ( resolve , reject ) => {
53- childProcess . on ( 'message' , ( message ) => {
54- if ( message === 'success' ) {
55- resolve ( ) ;
56- } else if ( message === 'error' ) {
57- reject ( new Error ( 'Error occurred in dts generation' ) ) ;
58- }
59- } ) ;
60- } ) ,
61- ) ;
62- } ) ;
56+ childProcess . send ( dtsGenOptions ) ;
57+
58+ dtsPromises . push (
59+ new Promise ( ( resolve , reject ) => {
60+ childProcess . on ( 'message' , ( message ) => {
61+ if ( message === 'success' ) {
62+ resolve ( ) ;
63+ } else if ( message === 'error' ) {
64+ reject (
65+ new Error (
66+ `Error occurred in ${ environment . name } dts generation` ,
67+ ) ,
68+ ) ;
69+ }
70+ } ) ;
71+ } ) ,
72+ ) ;
73+ } ,
74+ ) ;
75+
76+ api . onAfterBuild ( async ( { isFirstCompile } ) => {
77+ if ( ! isFirstCompile ) {
78+ return ;
79+ }
6380
64- api . onAfterBuild ( async ( ) => {
6581 await Promise . all ( dtsPromises ) ;
6682 } ) ;
6783 } ,
0 commit comments