svelte-vars
v0.1.0
Published
Repurpose your var declarations for reactive variables.
Downloads
2
Readme
Eyeballs tripping up over a couple of dollar signs? Do you exclusively use const and let in your code? Have a play with this.
To get started, here's an example of what your svelte.config.js file might look like when using this plugin in a SvelteKit project:
import { svelteVars } from 'svelte-vars'
export default {
preprocess: [ svelteVars(), vitePreprocess() ],
kit: { adapter: adapter() }
}
And within your Svelte components, you can now do the following:
<script lang="ts">
let value = 0;
// $: doubled = value * 2;
var doubled = value * 2;
const increment = () => val = val + 1
</script>
<button on:click={increment}>{doubled}</button>