Skip to content

Commit 3947596

Browse files
feat: SvelteKit reproducibility best practice (#196)
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent c5b0a45 commit 3947596

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

templates/sveltekit-example/svelte.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import adapter from '@sveltejs/adapter-static';
22
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
3+
import { readFileSync } from 'node:fs';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const file = fileURLToPath(new URL('package.json', import.meta.url));
7+
const json = readFileSync(file, 'utf8');
8+
const { version } = JSON.parse(json);
39

410
/** @type {import('@sveltejs/kit').Config} */
511
const config = {
@@ -11,7 +17,10 @@ const config = {
1117
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
1218
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
1319
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
14-
adapter: adapter()
20+
adapter: adapter(),
21+
version: {
22+
name: version
23+
}
1524
}
1625
};
1726

templates/sveltekit-starter/svelte.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import adapter from '@sveltejs/adapter-static';
22
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
3+
import { readFileSync } from 'node:fs';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const file = fileURLToPath(new URL('package.json', import.meta.url));
7+
const json = readFileSync(file, 'utf8');
8+
const { version } = JSON.parse(json);
39

410
/** @type {import('@sveltejs/kit').Config} */
511
const config = {
@@ -11,7 +17,10 @@ const config = {
1117
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
1218
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
1319
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
14-
adapter: adapter()
20+
adapter: adapter(),
21+
version: {
22+
name: version
23+
}
1524
}
1625
};
1726

0 commit comments

Comments
 (0)