@@ -211,8 +211,8 @@ export default async function microbundle(inputOptions) {
211211 }
212212
213213 if ( options . watch ) {
214- const onBuild = options . onBuild ;
215- return new Promise ( ( resolve , reject ) => {
214+ const { onStart , onBuild, onError } = options ;
215+ return new Promise ( resolve => {
216216 stdout (
217217 blue (
218218 `Watching source, compiling to ${ relative (
@@ -221,8 +221,9 @@ export default async function microbundle(inputOptions) {
221221 ) } :`,
222222 ) ,
223223 ) ;
224- steps . map ( options => {
225- watch (
224+
225+ const watchers = steps . reduce ( ( acc , options ) => {
226+ acc [ options . inputOptions . input ] = watch (
226227 Object . assign (
227228 {
228229 output : options . outputOptions ,
@@ -231,10 +232,16 @@ export default async function microbundle(inputOptions) {
231232 options . inputOptions ,
232233 ) ,
233234 ) . on ( 'event' , e => {
234- if ( e . code === 'FATAL' ) {
235- return reject ( e . error ) ;
236- } else if ( e . code === 'ERROR' ) {
235+ if ( e . code === 'START' ) {
236+ if ( typeof onStart === 'function' ) {
237+ onStart ( e ) ;
238+ }
239+ }
240+ if ( e . code === 'ERROR' ) {
237241 logError ( e . error ) ;
242+ if ( typeof onError === 'function' ) {
243+ onError ( e ) ;
244+ }
238245 }
239246 if ( e . code === 'END' ) {
240247 options . _sizeInfo . then ( text => {
@@ -245,7 +252,11 @@ export default async function microbundle(inputOptions) {
245252 }
246253 }
247254 } ) ;
248- } ) ;
255+
256+ return acc ;
257+ } , { } ) ;
258+
259+ resolve ( { watchers } ) ;
249260 } ) ;
250261 }
251262
@@ -263,14 +274,15 @@ export default async function microbundle(inputOptions) {
263274 } ) ,
264275 ) ;
265276
266- return (
267- blue (
268- `Build "${ options . name } " to ${ relative ( cwd , dirname ( options . output ) ) ||
269- '.' } :`,
270- ) +
271- '\n ' +
272- out . join ( '\n ' )
273- ) ;
277+ return {
278+ output :
279+ blue (
280+ `Build "${ options . name } " to ${ relative ( cwd , dirname ( options . output ) ) ||
281+ '.' } :`,
282+ ) +
283+ '\n ' +
284+ out . join ( '\n ' ) ,
285+ } ;
274286}
275287
276288async function getConfigFromPkgJson ( cwd ) {
0 commit comments