Skip to content

Commit c1885e2

Browse files
committed
feat(scripts): show cli output on browser-sync reload
See #444
1 parent e63aa9b commit c1885e2

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/scripts/src/bin/serve.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
printSuccessfullyCompiledMessage,
2121
printCompiledWithWarnMessage,
2222
printFailedCompileMEssage,
23+
printGeneralInfoMessage,
2324
} from './utils';
2425

2526
/**
@@ -114,6 +115,10 @@ export function serve(options: ProgramOptions | undefined): void {
114115
}
115116
printWatchingMessage();
116117
},
118+
onBsChange(file) {
119+
printGeneralInfoMessage(`changed: ${chalk.bold(file)}`);
120+
printGeneralInfoMessage('reloading browser');
121+
},
117122
});
118123
server.serve();
119124

packages/scripts/src/bin/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ ${chalk.bold(gradient.instagram(` \\_/\\_/`))} ${chalk.magenta(
2727
'v'
2828
)}${chalk.bold.magenta(`${pkg.version}`)}`;
2929

30+
export const wpackLogoSmall = gradient.instagram('wpack.io');
31+
3032
export function addTimeStampToLog(log: string): string {
3133
const time = new Date().toTimeString().split(' ')[0];
32-
return `${chalk.dim(`「wpack.io ${time}」`)} ${log}`;
34+
return `${chalk.dim(`「${wpackLogoSmall} ${time}」`)} ${log}`;
3335
}
3436

3537
export const watchSymbol = `${logSymbols.info}`;
@@ -77,8 +79,6 @@ export function printGeneralInfoMessage(msg: string) {
7779

7880
export const bulletSymbol = chalk.magenta(figures.pointer);
7981

80-
export const wpackLogoSmall = gradient.instagram('wpack.io');
81-
8282
export const wpackLink = `${chalk.blue.underline('https://wpack.io')}`;
8383

8484
export const wpackIntro = `${wpackLogo}\n`;

packages/scripts/src/scripts/Server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface Callbacks {
1616
firstCompile(stats: webpack.Stats): void;
1717
onError(err: { errors: string[]; warnings: string[] }): void;
1818
onWarn(warn: { errors: string[]; warnings: string[] }): void;
19+
onBsChange(file: string): void;
1920
}
2021

2122
/**
@@ -177,7 +178,10 @@ export class Server {
177178
if (this.projectConfig.watch) {
178179
bs.watch(this.projectConfig.watch as string).on(
179180
'change',
180-
bs.reload
181+
(file: string) => {
182+
this.callbacks.onBsChange(file);
183+
bs.reload();
184+
}
181185
);
182186
}
183187
// We don't need to watch for manifest, because if user is changing

0 commit comments

Comments
 (0)