Try making the compiled Elm garbage collectable by using the tip from https://gist.github.com/supermario/4c2615806c6c561a16edf5dd7208a759.

This commit is contained in:
Dillon Kearns 2021-05-18 06:53:04 -07:00
parent 246a9d8a06
commit f3937241e4
2 changed files with 19 additions and 4 deletions

View File

@ -14,10 +14,23 @@ async function spawnElmMake(elmEntrypointPath, outputPath, cwd) {
await fs.promises.writeFile(
fullOutputPath,
elmFileContent.replace(
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
"return " + (debug ? "_Json_wrap(x)" : "x")
)
elmFileContent
.replace(
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
"return " + (debug ? "_Json_wrap(x)" : "x")
)
.replace(
"return ports ? { ports: ports } : {};",
`const die = function() {
console.log('App dying')
managers = null
model = null
stepper = null
ports = null
}
return ports ? { ports: ports, die: die } : { die: die };`
)
);
}

View File

@ -81,6 +81,8 @@ function runElmApp(compiledElmPath, pagePath, request, addDataSourceWatcher) {
const args = fromElm.args[0];
global.staticHttpCache = args.staticHttpCache;
app.die();
delete require.cache[require.resolve(compiledElmPath)];
if (isJson) {
resolve({
kind: "json",