-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: render HTML when all compilers are ready in lazy mode (#424)
* Render HTML when all compilers are ready * Rename argument * Document api.compilers
- Loading branch information
1 parent
cf85e81
commit 12ce2a5
Showing
6 changed files
with
128 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { EventEmitter } = require('events') | ||
|
||
module.exports = class Compiler extends EventEmitter { | ||
constructor(type, api) { | ||
super() | ||
this.type = type | ||
this.api = api | ||
this.status = 'waiting' | ||
} | ||
|
||
injectToWebpack(config) { | ||
const ID = `compiler-${this.type}` | ||
const context = this | ||
config.plugin(ID).use( | ||
class { | ||
apply(compiler) { | ||
compiler.hooks.watchRun.tap(ID, () => { | ||
context.status = 'building' | ||
context.emit('status-changed', { | ||
status: context.status, | ||
allCompilers: { | ||
ready: false, | ||
hasError: false | ||
} | ||
}) | ||
}) | ||
compiler.hooks.done.tap(ID, stats => { | ||
if (stats.hasErrors()) { | ||
context.status = 'error' | ||
} else { | ||
context.status = 'success' | ||
} | ||
|
||
const allCompilers = { ready: true, hasError: false } | ||
Object.values(context.api.compilers).forEach(({ status }) => { | ||
if (status !== 'success' && status !== 'error') { | ||
allCompilers.ready = false | ||
} | ||
|
||
if (status === 'error') { | ||
allCompilers.hasError = true | ||
} | ||
}) | ||
|
||
context.emit('status-changed', { | ||
status: context.status, | ||
allCompilers | ||
}) | ||
}) | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters