在Svelte中的main.js中导入本地json [英] Importing local json in main.js in Svelte
本文介绍了在Svelte中的main.js中导入本地json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将JSON导入Svelte的main.js文件的方式是什么?
What is the pattern for importing JSON into Svelte's main.js file?
我正在尝试:
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;
但这无法解决,因为无法将JSON作为es6模块导入.
But this does not resolve as JSON cannot be imported as an es6 module.
推荐答案
Svelte不参与此过程-完全取决于捆绑程序.如果您使用汇总,则需要添加 rollup-plugin-json 插件插入您的rollup.config.js文件.
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.
这篇关于在Svelte中的main.js中导入本地json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文