-
-
Notifications
You must be signed in to change notification settings - Fork 372
feat: Less verbose error output #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,26 +26,30 @@ const devBuild = async (env, onprogress) => { | |
|
|
||
| let compiler = webpack(config); | ||
| return await new Promise((resolve, reject) => { | ||
| let first = true; | ||
|
|
||
| compiler.plugin('done', stats => { | ||
| if (first) { | ||
| first = false; | ||
| let devServer = config.devServer; | ||
| let devServer = config.devServer; | ||
|
|
||
| let protocol = devServer.https ? 'https' : 'http'; | ||
| let host = process.env.HOST || devServer.host || 'localhost'; | ||
|
|
||
| let protocol = devServer.https ? 'https' : 'http'; | ||
| let host = process.env.HOST || devServer.host || 'localhost'; | ||
| let serverAddr = `${protocol}://${host}:${chalk.bold(port)}`; | ||
| let localIpAddr = `${protocol}://${ip.address()}:${chalk.bold(port)}`; | ||
|
|
||
| let serverAddr = `${protocol}://${host}:${chalk.bold(port)}`; | ||
| let localIpAddr = `${protocol}://${ip.address()}:${chalk.bold(port)}`; | ||
| clearConsole(); | ||
| if (stats.hasErrors()) { | ||
| process.stdout.write(chalk.red('\Build failed!\n\n')); | ||
| } else { | ||
| process.stdout.write(chalk.green('\nCompiled successfully!\n\n')); | ||
|
|
||
| process.stdout.write(chalk.green('\nCompiled successfully!!\n\n')); | ||
| if (userPort !== port) { | ||
| process.stdout.write(`Port ${chalk.bold(userPort)} is in use, using ${chalk.bold(port)} instead\n\n`); | ||
| } | ||
| process.stdout.write('You can view the application in browser.\n\n'); | ||
| process.stdout.write(`${chalk.bold('Local:')} ${serverAddr}\n`); | ||
| process.stdout.write(`${chalk.bold('On Your Network:')} ${localIpAddr}\n`); | ||
| } | ||
|
|
||
| if (onprogress) onprogress(stats); | ||
| }); | ||
| compiler.plugin('failed', reject); | ||
|
|
@@ -71,7 +75,8 @@ const prodBuild = async (env) => { | |
| return await new Promise((resolve, reject) => { | ||
| compiler.run((err, stats) => { | ||
| if (err || stats.hasErrors()) { | ||
| reject(err || stats.toJson().errors.join('\n')); | ||
| showStats(stats); | ||
| reject(chalk.red('Build failed!')); | ||
| } | ||
| else { | ||
| // Timeout for plugins that work on `after-emit` event of webpack | ||
|
|
@@ -82,16 +87,16 @@ const prodBuild = async (env) => { | |
| }; | ||
|
|
||
| export function showStats(stats) { | ||
| let info = stats.toJson(); | ||
| let info = stats.toJson("errors-only"); | ||
|
|
||
| if (stats.hasErrors()) { | ||
| info.errors.forEach( message => { | ||
| process.stderr.write(message+'\n'); | ||
| info.errors.map(stripBabelLoaderPrefix).forEach( message => { | ||
| process.stderr.write(chalk.red(message)+'\n'); | ||
| }); | ||
| } | ||
|
|
||
| if (stats.hasWarnings()) { | ||
| info.warnings.forEach( message => { | ||
| info.warnings.map(stripBabelLoaderPrefix).forEach( message => { | ||
| process.stderr.write(chalk.yellow(message)+'\n'); | ||
| }); | ||
| } | ||
|
|
@@ -109,8 +114,8 @@ export function writeJsonStats(stats) { | |
|
|
||
| jsonStats = (jsonStats.children && jsonStats.children[0]) || jsonStats; | ||
|
|
||
| jsonStats.modules.forEach(normalizeModule); | ||
| jsonStats.chunks.forEach(c => c.modules.forEach(normalizeModule)); | ||
| jsonStats.modules.forEach(stripBabelLoaderFromModuleNames); | ||
| jsonStats.chunks.forEach(c => c.modules.forEach(stripBabelLoaderFromModuleNames)); | ||
|
|
||
| return fs.writeFile(outputPath, JSON.stringify(jsonStats)) | ||
| .then(() => { | ||
|
|
@@ -121,20 +126,26 @@ export function writeJsonStats(stats) { | |
| }); | ||
| } | ||
|
|
||
| const normalizeModule = m => { | ||
| const clearConsole = () => { | ||
| process.stdout.write( | ||
| process.platform === 'win32' ? '\x1Bc' : '\x1B[2J\x1B[3J\x1B[H' | ||
| ); | ||
| }; | ||
|
|
||
| const stripBabelLoaderFromModuleNames = m => { | ||
| const keysToNormalize = ['identifier', 'name', 'module', 'moduleName', 'moduleIdentifier']; | ||
|
|
||
| keysToNormalize.forEach(key => { | ||
| if (key in m) { | ||
| m[key] = normalizeName(m[key]); | ||
| m[key] = stripBabelLoaderPrefix(m[key]); | ||
| } | ||
| }); | ||
|
|
||
| if (m.reasons) { | ||
| m.reasons.forEach(normalizeModule); | ||
| m.reasons.forEach(stripBabelLoaderFromModuleNames); | ||
| } | ||
|
|
||
| return m; | ||
| }; | ||
|
|
||
| const normalizeName = p => p.substr(p.lastIndexOf('!') + 1); | ||
| const stripBabelLoaderPrefix = log => log.replace(/@?\s*(\.\/~\/babel-loader\/lib\?{[\s\S]*?}!)/g, ''); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a boatload more of these transforms we can add, I'll get clearance to release them shortly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would love to see those boatload of transforms @developit ! |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this since it is better to clear off the console when there is an error and show the network interface when build is successful (every time)