forked from nasa-gcn/web-dev-bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin-remix.mjs
49 lines (45 loc) · 1.31 KB
/
plugin-remix.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This should eventually be a npm package, but for now it lives here.
// It's job is to notify the remix dev server of the version of the running
// app to trigger HMR / HDR.
import { logDevReady } from '@remix-run/node'
import * as fs from 'node:fs'
import * as path from 'node:path'
const buildPath = 'build/server/index.js'
let lastTimeout
export default {
sandbox: {
async watcher() {
if (lastTimeout) {
clearTimeout(lastTimeout)
}
lastTimeout = setTimeout(async () => {
const contents = fs.readFileSync(
path.resolve(process.cwd(), buildPath),
'utf8'
)
const manifestMatches = contents.matchAll(
/manifest-([A-Fa-f0-9]+)\.js/g
)
const sent = new Set()
for (const match of manifestMatches) {
const buildHash = match[1]
if (!sent.has(buildHash)) {
sent.add(buildHash)
logDevReady({ assets: { version: buildHash } })
}
}
}, 300)
},
},
set: {
env() {
// Pass matching env variables through to the application in dev mode.
const passthruKeys = /^NODE_ENV$|^REMIX_DEV_/
return {
testing: Object.fromEntries(
Object.entries(process.env).filter(([key]) => passthruKeys.test(key))
),
}
},
},
}