chore: minimal webpack stats

This commit is contained in:
Pooya Parsa 2021-02-17 21:15:47 +01:00
parent 64ca193ac9
commit c2d93aa55a
2 changed files with 21 additions and 18 deletions

View File

@ -1,8 +1,9 @@
import { resolve, normalize } from 'path' import { resolve, normalize } from 'path'
import TimeFixPlugin from 'time-fix-plugin' import TimeFixPlugin from 'time-fix-plugin'
import WebpackBar from 'webpackbar' import WebpackBar from 'webpackbar'
import consola from 'consola'
import { DefinePlugin, Configuration } from 'webpack' import { DefinePlugin, Configuration } from 'webpack'
// import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin' import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
import { isUrl, urlJoin, TARGETS } from 'src/utils' import { isUrl, urlJoin, TARGETS } from 'src/utils'
import escapeRegExp from 'lodash/escapeRegExp' import escapeRegExp from 'lodash/escapeRegExp'
import WarningIgnorePlugin from '../plugins/warning-ignore' import WarningIgnorePlugin from '../plugins/warning-ignore'
@ -33,7 +34,7 @@ function baseConfig (ctx: WebpackConfigContext) {
mode: ctx.isDev ? 'development' : 'production', mode: ctx.isDev ? 'development' : 'production',
cache: getCache(ctx), cache: getCache(ctx),
output: getOutput(ctx), output: getOutput(ctx),
stats: 'errors-warnings', stats: 'none',
...ctx.config ...ctx.config
} }
} }
@ -56,18 +57,18 @@ function basePlugins (ctx: WebpackConfigContext) {
config.plugins.push(new DefinePlugin(getEnv(ctx))) config.plugins.push(new DefinePlugin(getEnv(ctx)))
// Friendly errors // Friendly errors
// if ( if (
// ctx.isServer || ctx.isServer ||
// (ctx.isDev && !options.build.quiet && options.build.friendlyErrors) (ctx.isDev && !options.build.quiet && options.build.friendlyErrors)
// ) { ) {
// ctx.config.plugins.push( ctx.config.plugins.push(
// new FriendlyErrorsWebpackPlugin({ new FriendlyErrorsWebpackPlugin({
// clearConsole: false, clearConsole: false,
// reporter: 'consola', reporter: 'consola',
// logLevel: 'WARNING' logLevel: 'ERROR' // TODO
// }) })
// ) )
// } }
// Webpackbar // Webpackbar
const colors = { const colors = {
@ -78,8 +79,7 @@ function basePlugins (ctx: WebpackConfigContext) {
config.plugins.push(new WebpackBar({ config.plugins.push(new WebpackBar({
name: ctx.name, name: ctx.name,
color: colors[ctx.name], color: colors[ctx.name],
reporters: ['basic', 'stats'], reporters: ['stats'],
basic: true,
stats: !ctx.isDev, stats: !ctx.isDev,
reporter: { reporter: {
change: (_, { shortPath }) => { change: (_, { shortPath }) => {
@ -87,9 +87,11 @@ function basePlugins (ctx: WebpackConfigContext) {
nuxt.callHook('bundler:change', shortPath) nuxt.callHook('bundler:change', shortPath)
} }
}, },
done: (stats) => { done: ({ state }) => {
if (stats.hasErrors) { if (state.hasErrors) {
nuxt.callHook('bundler:error') nuxt.callHook('bundler:error')
} else {
consola.success(`${state.name} ${state.message}`)
} }
}, },
allDone: () => { allDone: () => {

View File

@ -178,6 +178,7 @@ class WebpackBundler {
compiler, { compiler, {
publicPath: buildOptions.publicPath, publicPath: buildOptions.publicPath,
outputFileSystem: this.mfs, outputFileSystem: this.mfs,
stats: 'none',
...buildOptions.devMiddleware ...buildOptions.devMiddleware
}) })
) )