Merge pull request #1469 from h3poteto/fix/hot-reload

Fix hotcode reload for new html-webpack-plugin
This commit is contained in:
AkiraFukushima 2020-05-23 22:00:16 +09:00 committed by GitHub
commit 350c82af65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 37 deletions

View File

@ -19,14 +19,17 @@ let hotMiddleware
function logStats(proc, data) {
let log = ''
log += chalk.yellow.bold(`${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`)
log += chalk.yellow.bold(`${proc} Process ${new Array(19 - proc.length + 1).join('-')}`)
log += '\n\n'
if (typeof data === 'object') {
data.toString({
data
.toString({
colors: true,
chunks: false
}).split(/\r?\n/).forEach(line => {
})
.split(/\r?\n/)
.forEach(line => {
log += ' ' + line + '\n'
})
} else {
@ -49,7 +52,8 @@ function startRenderer () {
})
compiler.hooks.compilation.tap('compilation', compilation => {
compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
const HtmlWebpackPlugin = require('html-webpack-plugin')
HtmlWebpackPlugin.getHooks(compilation).afterEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
hotMiddleware.publish({ action: 'reload' })
cb()
})
@ -59,9 +63,7 @@ function startRenderer () {
logStats('Renderer', stats)
})
const server = new WebpackDevServer(
compiler,
{
const server = new WebpackDevServer(compiler, {
contentBase: path.join(__dirname, '../'),
quiet: true,
before(app, ctx) {
@ -70,8 +72,7 @@ function startRenderer () {
resolve()
})
}
}
)
})
server.listen(9080)
})
@ -128,10 +129,7 @@ function startElectron () {
})
}
function startElectron() {
var args = [
'--inspect=5858',
path.join(__dirname, '../dist/electron/main.js')
]
var args = ['--inspect=5858', path.join(__dirname, '../dist/electron/main.js')]
// detect yarn or npm and process commandline args accordingly
if (process.env.npm_execpath.endsWith('yarn.js')) {
@ -162,11 +160,7 @@ function electronLog (data, color) {
})
if (/[0-9A-z]+/.test(log)) {
console.log(
chalk[color].bold('┏ Electron -------------------') +
'\n\n' +
log +
chalk[color].bold('┗ ----------------------------') +
'\n'
chalk[color].bold('┏ Electron -------------------') + '\n\n' + log + chalk[color].bold('┗ ----------------------------') + '\n'
)
}
}