Created
September 26, 2024 18:39
-
-
Save lazuee/092de0b74d856c8658d1de8874f1678f to your computer and use it in GitHub Desktop.
ESM import cache busting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from "node:fs"; | |
import * as path from "node:path"; | |
let build = await reimport(path.resolve("build/index.js")); | |
export async function reimport(path) { | |
const stat = fs.statSync(path); | |
// convert build path to URL for Windows compatibility with dynamic `import` | |
const BUILD_URL = url.pathToFileURL(path).href; | |
// use a timestamp query parameter to bust the import cache | |
return import(BUILD_URL + "?t=" + stat.mtimeMs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment