parallel builds + new progress bar

This commit is contained in:
Pooya Parsa 2018-03-12 02:45:14 +03:30
parent a354d2fa55
commit 9fe564b8f2
5 changed files with 70 additions and 58 deletions

View File

@ -2,6 +2,7 @@ const { promisify } = require('util')
const _ = require('lodash')
const chokidar = require('chokidar')
const { remove, readFile, writeFile, mkdirp, existsSync } = require('fs-extra')
const fs = require('fs')
const hash = require('hash-sum')
const webpack = require('webpack')
const serialize = require('serialize-javascript')
@ -11,15 +12,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const Debug = require('debug')
const Glob = require('glob')
const {
r,
wp,
wChunk,
createRoutes,
sequence,
relativeTo,
waitFor
} = require('../common/utils')
const { r, wp, wChunk, createRoutes, parallel, relativeTo, waitFor } = require('../common/utils')
const { Options } = require('../common')
const clientWebpackConfig = require('./webpack/client.config.js')
const serverWebpackConfig = require('./webpack/server.config.js')
@ -476,7 +469,6 @@ module.exports = class Builder {
// Initialize shared FS and Cache
const sharedFS = this.options.dev && new MFS()
const sharedCache = {}
// Initialize compilers
this.compilers = compilersOptions.map(compilersOption => {
@ -485,12 +477,12 @@ module.exports = class Builder {
if (sharedFS) {
compiler.outputFileSystem = sharedFS
}
compiler.cache = sharedCache
return compiler
})
// Start Builds
await sequence(
await parallel(
this.compilers,
compiler =>
new Promise(async (resolve, reject) => {
@ -505,7 +497,7 @@ module.exports = class Builder {
stats
})
// Reload renderer if available
this.nuxt.renderer.loadResources(sharedFS || require('fs'))
this.nuxt.renderer.loadResources(sharedFS || fs)
// Resolve on next tick
process.nextTick(resolve)
})

View File

@ -1,10 +1,9 @@
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
const TimeFixPlugin = require('time-fix-plugin')
const WarnFixPlugin = require('./plugins/warnfix')
const webpack = require('webpack')
const ProgressPlugin = require('./plugins/progress')
const Chalk = require('chalk')
const { cloneDeep } = require('lodash')
const { join, resolve } = require('path')
@ -129,22 +128,15 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
plugins: this.options.build.plugins
}
// Build progress bar
// Build progress indicator
if (this.options.build.profile) {
config.plugins.push(
new ProgressPlugin({
profile: true
})
)
config.plugins.push(new webpack.ProgressPlugin({ profile: true }))
} else {
config.plugins.push(
new ProgressBarPlugin({
complete: Chalk.green('█'),
incomplete: Chalk.white('█'),
format: ' :bar ' + Chalk.green.bold(':percent') + ' :msg',
clear: false
})
)
config.plugins.push(new ProgressPlugin({
color: isServer ? 'yellow' : 'green',
pcolor: isServer ? 'gradient(red,yellow)' : 'gradient(green,cyan)',
title: isServer ? 'SSR ' : 'CLIENT'
}))
}
// Add timefix-plugin before others plugins

View File

@ -0,0 +1,17 @@
const ProgressBar = require('node-progress-bars')
const webpack = require('webpack')
module.exports = function ProgressPlugin({ color, pcolor, title }) {
// https://github.com/bubkoo/ascii-progress
const bar = new ProgressBar({
schema: `${title}.${color} >.grey :filled.${pcolor}:blank.white :msg.grey`,
filled: '█',
blank: '█',
total: 100,
width: 25
})
return new webpack.ProgressPlugin((percent, msg) => {
bar.update(percent, { msg })
})
}

View File

@ -89,6 +89,7 @@
"lru-cache": "^4.1.2",
"memory-fs": "^0.4.1",
"minimist": "^1.2.0",
"node-progress-bars": "^1.0.8",
"opencollective": "^1.0.3",
"postcss": "^6.0.17",
"postcss-cssnext": "^3.1.0",
@ -97,7 +98,6 @@
"postcss-loader": "^2.1.0",
"postcss-url": "^7.3.0",
"pretty-error": "^2.1.1",
"progress-bar-webpack-plugin": "^1.11.0",
"semver": "^5.5.0",
"serialize-javascript": "^1.4.0",
"serve-static": "^1.13.2",

View File

@ -271,6 +271,12 @@ ansi-styles@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178"
ansi.js@0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/ansi.js/-/ansi.js-0.0.5.tgz#e3e9e45eb6977ba0eeeeed11677d12144675348c"
dependencies:
on-new-line "0.0.1"
anymatch@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
@ -1573,7 +1579,7 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"
chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
dependencies:
@ -2606,6 +2612,10 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
dependencies:
once "^1.4.0"
end-with@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/end-with/-/end-with-1.0.2.tgz#a432755ab4f51e7fc74f3a719c6b81df5d668bdc"
enhanced-resolve@^3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
@ -3338,6 +3348,10 @@ get-caller-file@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
get-cursor-position@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/get-cursor-position/-/get-cursor-position-1.0.5.tgz#1558c35aa056726eae704d5590aeaa5945989f5a"
get-port@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
@ -3518,10 +3532,6 @@ has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
has-symbols@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.0.tgz#ba1a8f1af2a0fc39650f5c850367704122063b44"
has-unicode@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
@ -5028,6 +5038,16 @@ node-pre-gyp@^0.6.39:
tar "^2.2.1"
tar-pack "^3.4.0"
node-progress-bars@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/node-progress-bars/-/node-progress-bars-1.0.8.tgz#ddcbfb66657f2a4fd4e8f2fce00bc324b5cb9535"
dependencies:
ansi.js "0.0.5"
end-with "^1.0.2"
get-cursor-position "^1.0.4"
on-new-line "1.0.0"
start-with "^1.0.2"
nopt@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
@ -5144,7 +5164,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"
object-keys@^1.0.11, object-keys@^1.0.8:
object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
@ -5154,15 +5174,6 @@ object-visit@^1.0.0:
dependencies:
isobject "^3.0.0"
object.assign@^4.0.1:
version "4.1.0"
resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da"
dependencies:
define-properties "^1.1.2"
function-bind "^1.1.1"
has-symbols "^1.0.0"
object-keys "^1.0.11"
object.getownpropertydescriptors@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16"
@ -5200,6 +5211,14 @@ on-headers@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.1.tgz#928f5d0f470d49342651ea6794b0857c100693f7"
on-new-line@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/on-new-line/-/on-new-line-0.0.1.tgz#99339cb06dcfe3e78d6964a2ef2af374a145f8fb"
on-new-line@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/on-new-line/-/on-new-line-1.0.0.tgz#8585bc2866c8c0e192e410a6d63bdd1722148ae7"
once@^1.3.0, once@^1.3.1, once@^1.3.3, once@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
@ -6138,18 +6157,6 @@ process@^0.11.10:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
progress-bar-webpack-plugin@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/progress-bar-webpack-plugin/-/progress-bar-webpack-plugin-1.11.0.tgz#4f801288443c55ec029b20cbfdcbf3e1dc17f852"
dependencies:
chalk "^1.1.1"
object.assign "^4.0.1"
progress "^1.1.8"
progress@^1.1.8:
version "1.1.8"
resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be"
progress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"
@ -7076,6 +7083,10 @@ stackframe@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.0.4.tgz#357b24a992f9427cba6b545d96a14ed2cbca187b"
start-with@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/start-with/-/start-with-1.0.2.tgz#a069a5f46a95fca7f0874f85a28f653d0095c267"
static-extend@^0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"