What is the pattern for importing JSON into Svelte's main.js file?
I'm trying:
import App from './App.html';
const dataset = require('./../posts.json');
console.log(dataset);
const app = new App({
target: document.body,
data: dataset
});
export default app;
But this does not resolve as JSON cannot be imported as an es6 module.
Svelte isn't involved in this process — it's entirely up to your bundler. If you're using Rollup, you'll need to add the rollup-plugin-json plugin to your rollup.config.js file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With