mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-02 18:37:21 +00:00
fix: Implement TimeFixPlugin by @egoist to avoid webpack rebuilds
This commit is contained in:
parent
e05da610c8
commit
6dfe660412
@ -1,6 +1,6 @@
|
|||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import chokidar from 'chokidar'
|
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 hash from 'hash-sum'
|
||||||
import pify from 'pify'
|
import pify from 'pify'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
@ -366,9 +366,6 @@ export default class Builder {
|
|||||||
await mkdirp(dirname(path))
|
await mkdirp(dirname(path))
|
||||||
// Write file
|
// Write file
|
||||||
await writeFile(path, content, 'utf8')
|
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 { join, resolve } from 'path'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import { isUrl, urlJoin } from 'utils'
|
import { isUrl, urlJoin } from 'utils'
|
||||||
|
import TimeFixPlugin from './timefix-plugin'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@ -104,6 +105,9 @@ export default function webpackBaseConfig(name) {
|
|||||||
plugins: this.options.build.plugins
|
plugins: this.options.build.plugins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add timefix-plugin before others plugins
|
||||||
|
config.plugins.unshift(new TimeFixPlugin())
|
||||||
|
|
||||||
// CSS extraction
|
// CSS extraction
|
||||||
if (this.options.build.extractCSS) {
|
if (this.options.build.extractCSS) {
|
||||||
config.plugins.push(new ExtractTextPlugin({
|
config.plugins.push(new ExtractTextPlugin({
|
||||||
|
18
lib/builder/webpack/timefix-plugin.js
Normal file
18
lib/builder/webpack/timefix-plugin.js
Normal file
@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user