Skip to content

Commit d11c5b3

Browse files
committed
Touch the first page to speed up the future rebuild times.
1 parent ddf6a0c commit d11c5b3

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"source-map-support": "0.4.11",
8080
"strip-ansi": "3.0.1",
8181
"styled-jsx": "0.5.7",
82+
"touch": "^1.0.0",
8283
"url": "0.11.0",
8384
"uuid": "3.0.1",
8485
"webpack": "2.2.1",

server/on-demand-entry-handler.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventEmitter } from 'events'
33
import { join } from 'path'
44
import { parse } from 'url'
55
import resolvePath from './resolve'
6+
import touch from 'touch'
67

78
const ADDED = Symbol()
89
const BUILDING = Symbol()
@@ -16,6 +17,7 @@ export default function onDemandEntryHandler (devMiddleware, compiler, {
1617
const entries = {}
1718
const lastAccessPages = ['']
1819
const doneCallbacks = new EventEmitter()
20+
let touchedAPage = false
1921

2022
compiler.plugin('make', function (compilation, done) {
2123
const allEntries = Object.keys(entries).map((page) => {
@@ -35,6 +37,17 @@ export default function onDemandEntryHandler (devMiddleware, compiler, {
3537
const entryInfo = entries[page]
3638
if (entryInfo.status !== BUILDING) return
3739

40+
// With this, we are triggering a filesystem based watch trigger
41+
// It'll memorize some timestamp related info related to common files used
42+
// in the page
43+
// That'll reduce the page building time significantly.
44+
if (!touchedAPage) {
45+
setTimeout(() => {
46+
touch.sync(entryInfo.pathname)
47+
}, 0)
48+
touchedAPage = true
49+
}
50+
3851
entryInfo.status = BUILT
3952
entries[page].lastActiveTime = Date.now()
4053
doneCallbacks.emit(page)
@@ -76,7 +89,7 @@ export default function onDemandEntryHandler (devMiddleware, compiler, {
7689

7790
console.log(`> Building page: ${page}`)
7891

79-
entries[page] = { name, entry, status: ADDED }
92+
entries[page] = { name, entry, pathname, status: ADDED }
8093
doneCallbacks.on(page, processCallback)
8194

8295
devMiddleware.invalidate()

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,12 @@ node-pre-gyp@^0.6.29:
34683468
tar "~2.2.1"
34693469
tar-pack "~3.3.0"
34703470

3471+
nopt@~1.0.10:
3472+
version "1.0.10"
3473+
resolved "https://registry.yarnpkg.com/nopt/-/nopt-1.0.10.tgz#6ddd21bd2a31417b92727dd585f8a6f37608ebee"
3474+
dependencies:
3475+
abbrev "1"
3476+
34713477
nopt@~3.0.1, nopt@~3.0.6:
34723478
version "3.0.6"
34733479
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
@@ -4596,6 +4602,12 @@ to-fast-properties@^1.0.1:
45964602
version "1.0.2"
45974603
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.2.tgz#f3f5c0c3ba7299a7ef99427e44633257ade43320"
45984604

4605+
touch@^1.0.0:
4606+
version "1.0.0"
4607+
resolved "https://registry.yarnpkg.com/touch/-/touch-1.0.0.tgz#449cbe2dbae5a8c8038e30d71fa0ff464947c4de"
4608+
dependencies:
4609+
nopt "~1.0.10"
4610+
45994611
tough-cookie@^2.3.2, tough-cookie@~2.3.0:
46004612
version "2.3.2"
46014613
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a"

0 commit comments

Comments
 (0)