Skip to content

Commit e73a8fe

Browse files
authored
Merge pull request #235 from mjancarik/usa-3912
fix: 🐛 Fix HMR when the task's build.write is true
2 parents 4597cf0 + b0907a2 commit e73a8fe

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

packages/cli/src/plugins/devPlugin.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'node:crypto';
12
import fs from 'node:fs';
23

34
import chalk from 'chalk';
@@ -7,6 +8,12 @@ import { createClient } from '../websocket.mjs';
78
import { createLogger } from '../logger.mjs';
89
import { COMMAND_NAME } from '../commands/constant.mjs';
910

11+
function getFileHash(filePath) {
12+
const fileContent = fs.readFileSync(filePath, 'utf-8');
13+
14+
return crypto.createHash('md5').update(fileContent).digest('hex');
15+
}
16+
1017
export function devPlugin({ definition, merkurConfig, cliConfig }) {
1118
const logger = createLogger('devPlugin', cliConfig);
1219
const { projectFolder, buildFolder } = cliConfig;
@@ -44,8 +51,15 @@ export function devPlugin({ definition, merkurConfig, cliConfig }) {
4451
};
4552
});
4653

54+
const outputFiles =
55+
result?.outputFiles ??
56+
Object.keys(result?.metafile?.outputs || {}).map((key) => ({
57+
path: key,
58+
hash: getFileHash(key),
59+
}));
60+
4761
changed =
48-
result?.outputFiles?.reduce((changed, file) => {
62+
outputFiles?.reduce((changed, file) => {
4963
const name = file.path
5064
.replace(projectFolder, '')
5165
.replace(buildFolder, '')

0 commit comments

Comments
 (0)