Skip to content

Commit

Permalink
fix(ui): DashboardPlugin clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 26, 2018
1 parent 1e3a499 commit 0ac38da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
5 changes: 2 additions & 3 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ module.exports = (api, options) => {
if (args.dashboard) {
const DashboardPlugin = require('../webpack/DashboardPlugin')
;(webpackConfig.plugins = webpackConfig.plugins || []).push(new DashboardPlugin({
type: 'serve',
gzip: false,
minified: false
type: 'serve'
}))
}

Expand Down Expand Up @@ -122,6 +120,7 @@ module.exports = (api, options) => {
openBrowser(urls.localUrlForBrowser)
}

// Send final app URL
if (args.dashboard) {
const ipc = new IpcMessenger()
ipc.connect()
Expand Down
38 changes: 16 additions & 22 deletions packages/@vue/cli-service/lib/webpack/DashboardPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,24 @@ function getTimeMessage (timer) {

class DashboardPlugin {
constructor (options) {
if (typeof options === 'function') {
this.handler = options
} else {
options = options || {}
this.handler = options.handler || null
this.type = options.type
}

this.cleanup = this.cleanup.bind(this)

this.type = options.type
this.watching = false
}

cleanup () {
if (!this.watching) {
this.handler = null
}
this.sendData = null
ipc.disconnect()
}

apply (compiler) {
let handler = this.handler
let sendData = this.sendData
let timer

let assetSources

if (!handler) {
if (!sendData) {
ipc.connect()
handler = data => ipc.send({
sendData = data => ipc.send({
webpackDashboardData: {
type: this.type,
value: data
Expand All @@ -70,10 +59,11 @@ class DashboardPlugin {

compiler.apply(
new webpack.ProgressPlugin((percent, msg) => {
// Debouncing
const time = Date.now()
if (time - progressTime > 100) {
progressTime = time
handler([
sendData([
{
type: 'status',
value: 'Compiling'
Expand Down Expand Up @@ -104,7 +94,7 @@ class DashboardPlugin {
compiler.plugin('compile', () => {
timer = Date.now()

handler([
sendData([
{
type: 'status',
value: 'Compiling'
Expand All @@ -113,7 +103,7 @@ class DashboardPlugin {
})

compiler.plugin('invalid', () => {
handler([
sendData([
{
type: 'status',
value: 'Invalidated'
Expand All @@ -130,7 +120,7 @@ class DashboardPlugin {
})

compiler.plugin('failed', () => {
handler([
sendData([
{
type: 'status',
value: 'Failed'
Expand Down Expand Up @@ -164,11 +154,12 @@ class DashboardPlugin {
asset.name = asset.name.replace(FILENAME_QUERY_REGEXP, '')
asset.fullPath = path.join(outputPath, asset.name)
})
// Analyze the assets and update sizes on assets and modules
analyzeBundle(statsData, assetSources)

const hasErrors = stats.hasErrors()

handler([
sendData([
{
type: 'status',
value: hasErrors ? 'Failed' : 'Success'
Expand All @@ -190,7 +181,10 @@ class DashboardPlugin {
}
}
])
this.cleanup()

if (!this.watching) {
this.cleanup()
}
})
}
}
Expand Down

0 comments on commit 0ac38da

Please sign in to comment.