Skip to content

Commit

Permalink
Use mtime as timestamp when loading config file
Browse files Browse the repository at this point in the history
Co-authored-by: Conduitry <git@chor.date>
  • Loading branch information
benmccann and Conduitry committed May 31, 2022
1 parent 12c5a9b commit 3c39fae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-months-explode.md
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

Use last modified time as cache busting parameter
8 changes: 6 additions & 2 deletions packages/vite-plugin-svelte/src/utils/load-svelte-config.ts
Expand Up @@ -22,7 +22,8 @@ export const knownSvelteConfigNames = [
// also use timestamp query to avoid caching on reload
const dynamicImportDefault = new Function(
'path',
'return import(path + "?t=" + Date.now()).then(m => m.default)'
'timestamp',
'return import(path + "?t=" + timestamp).then(m => m.default)'
);

export async function loadSvelteConfig(
Expand All @@ -38,7 +39,10 @@ export async function loadSvelteConfig(
// try to use dynamic import for svelte.config.js first
if (configFile.endsWith('.js') || configFile.endsWith('.mjs')) {
try {
const result = await dynamicImportDefault(pathToFileURL(configFile).href);
const result = await dynamicImportDefault(
pathToFileURL(configFile).href,
fs.statSync(configFile).mtimeMs
);
if (result != null) {
return {
...result,
Expand Down

0 comments on commit 3c39fae

Please sign in to comment.