'How to display a package.json version in the footer of the site?
I would like to display a version that is declared in the package.json file in the footer of my site
How can I do this?
I found this FAQ explanation in their documentation, but unfortunately I don't know to access it from my component
// svelte.config.js
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
const file = fileURLToPath(new URL('package.json', import.meta.url));
const json = readFileSync(file, 'utf8');
const pkg = JSON.parse(json);
Solution 1:[1]
You can use vite.define
to do this:
const config = {
kit: {
vite: {
define: {
VERSION: pkg
}
}
}
};
and in your component:
<script>
const version = VERSION;
</script>
<span>{version}</span>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Stephane Vanraes |