svelte-preprocessor-fetch
A preprocessor for Svelte that can be used to fetch data before components are compiled.
Demos
Installation
yarn add -D svelte-preprocessor-fetch
Usage
rollup-plugin-svelte
With // rollup.config.js; ... plugins:
In components
Create a function called getStaticProps()
in your script tag and do your fetches here. The content of this function must be fully self-container. You can not use any variables from outside or import any packages. It has support for fetch via node-fetch
.
The data is available using as data
in your component.
Continents: {#each data.continents as { name }} {name} {/each}
Caveats
This preprocessor is probably extremely brittle, PRs are welcome to improve it further.