-
Notifications
You must be signed in to change notification settings - Fork 96
/
plugin-remix.js
49 lines (43 loc) · 1.3 KB
/
plugin-remix.js
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.
// Its job is to notify the remix dev server of the version of the running
// app to trigger HMR / HDR.
import * as fs from "node:fs";
import * as path from "node:path";
import { logDevReady } from "@remix-run/node";
const buildPath = "server/index.mjs";
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-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)),
),
};
},
},
};