Skip to content

Commit

Permalink
feat: show first-time build errors (if any)
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
swashata committed Nov 3, 2018
1 parent ae32d63 commit a22b6d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
33 changes: 32 additions & 1 deletion packages/scripts/src/bin/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ora from 'ora';
import path from 'path';
import PrettyError from 'pretty-error';
import clearConsole from 'react-dev-utils/clearConsole';
import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages';
import webpack from 'webpack';
import { getProjectAndServerConfig } from '../config/getProjectAndServerConfig';
import { WpackioError } from '../errors/WpackioError';
import { Server } from '../scripts/Server';
Expand Down Expand Up @@ -116,13 +118,42 @@ export function serve(options: ProgramOptions | undefined): void {
`${watchSymbol} watching for changes${watchEllipsis}`
);
},
firstCompile: () => {
firstCompile: (stats: webpack.Stats) => {
spinner.stop();
const raw = stats.toJson('verbose');
const messages = formatWebpackMessages(raw);
clearConsole();
serverInfo(server.getServerUrl(), server.getBsUiUrl());
console.log(
`${logSymbols.success} ${chalk.dim('server started!')}`
);
if (stats.hasErrors()) {
console.log(
`${chalk.bgRed.black(' ERROR ')} please review`
);
messages.errors.forEach(e => console.log(e));
console.log('');
console.error(
`${logSymbols.error} ${chalk.dim(
'failed to compile'
)}\n`
);
} else {
if (stats.hasWarnings()) {
console.log(
`${logSymbols.warning} ${chalk.dim(
'compiled with warnings...'
)}\n`
);
messages.warnings.forEach(e => console.log(e));
} else {
console.log(
`${logSymbols.success} ${chalk.dim(
'compiled successfully'
)}\n`
);
}
}
console.log(
`${watchSymbol} watching for changes${watchEllipsis}`
);
Expand Down
6 changes: 3 additions & 3 deletions packages/scripts/src/scripts/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ServerConfig } from '../config/server.config.default';
interface Callbacks {
invalid(): void;
done(stats: webpack.Stats): void;
firstCompile(): void;
firstCompile(stats: webpack.Stats): void;
onError(err: { errors: string[]; warnings: string[] }): void;
onWarn(warn: { errors: string[]; warnings: string[] }): void;
}
Expand Down Expand Up @@ -141,9 +141,9 @@ export class Server {
});

// Open browser on first build
devMiddleware.waitUntilValid(() => {
devMiddleware.waitUntilValid(stats => {
if (!this.firstCompileCompleted) {
this.callbacks.firstCompile();
this.callbacks.firstCompile(stats);
this.firstCompileCompleted = true;
}
this.openBrowser();
Expand Down

0 comments on commit a22b6d5

Please sign in to comment.