Reputation: 8150
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.
Upvotes: 7
Views: 7774
Reputation: 29605
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.
Upvotes: 13