Permalink
Browse files

fix: Implement TimeFixPlugin by @egoist to avoid webpack rebuilds

  • Loading branch information...
Atinux committed Nov 7, 2017
1 parent e05da61 commit 6dfe6604129b1eff7a6991d6b4259a723181de19
Showing with 23 additions and 4 deletions.
  1. +1 −4 lib/builder/builder.js
  2. +4 −0 lib/builder/webpack/base.config.js
  3. +18 −0 lib/builder/webpack/timefix-plugin.js
View
@@ -1,6 +1,6 @@
import _ from 'lodash'
import chokidar from 'chokidar'
import fs, { remove, readFile, writeFile, mkdirp, utimes, existsSync } from 'fs-extra'
import fs, { remove, readFile, writeFile, mkdirp, existsSync } from 'fs-extra'
import hash from 'hash-sum'
import pify from 'pify'
import webpack from 'webpack'
@@ -366,9 +366,6 @@ export default class Builder {
await mkdirp(dirname(path))
// Write file
await writeFile(path, content, 'utf8')
// Fix webpack loop (https://github.com/webpack/watchpack/issues/25#issuecomment-287789288)
const dateFS = Date.now() / 1000 - 1000
return utimes(path, dateFS, dateFS)
}))
}
@@ -3,6 +3,7 @@ import { cloneDeep } from 'lodash'
import { join, resolve } from 'path'
import webpack from 'webpack'
import { isUrl, urlJoin } from 'utils'
import TimeFixPlugin from './timefix-plugin'
/*
|--------------------------------------------------------------------------
@@ -104,6 +105,9 @@ export default function webpackBaseConfig(name) {
plugins: this.options.build.plugins
}
// Add timefix-plugin before others plugins
config.plugins.unshift(new TimeFixPlugin())
// CSS extraction
if (this.options.build.extractCSS) {
config.plugins.push(new ExtractTextPlugin({
@@ -0,0 +1,18 @@
// Taken from https://github.com/egoist/poi/blob/3e93c88c520db2d20c25647415e6ae0d3de61145/packages/poi/lib/webpack/timefix-plugin.js#L1-L16
// Thanks to @egoist
export default class TimeFixPlugin {
constructor(timefix = 11000) {
this.timefix = timefix
}
apply(compiler) {
compiler.plugin('watch-run', (watching, callback) => {
watching.startTime += this.timefix
callback()
})
compiler.plugin('done', stats => {
stats.startTime -= this.timefix
})
}
}

0 comments on commit 6dfe660

Please sign in to comment.