-
|
Hey folks, I don't know how to do this, so I'm posting this question here to see if anyone can help me! I have an open source project of a Tabletop RPG System using Since it's an RPG Book, It has a lot of Skills, and each Skill is being currently defined in a JSON file, inside the Then I import those JSON files into the markdown pages, so they can be used by a React component: But, the process to import those Json files can be quite problematic, since I need to repeat the import for every place I want to use the JSON. So basically what I wanted was to have something like this: // Example of a JSON file double_fist.json
{
"name": "Punho Duplo",
"magic_cost": "2x P.M",
"duration_time": null,
"attack_logic": null,
"action_type": "Aprimoramento",
"cast_distance": null,
"range_amount": null,
"range_type": null,
"icon": "GiDigHole",
"element": null,
"caption": "Você é o mestre dos Punhos de Mago, conseguindo desferir dois ataques poderosos simultaneamente.",
"description": "<p>Aprimora o Punhos de Mago, desferindo dois Punhos de Mago em uma única ação. Cada ataque precisa ser testado separadamente e precisa acertar o mesmo alvo.</p>",
"tags": ["grimo", "orbe-de-allura"]
}Compiled to the output file into something like this: export const DoubleFist = {
"name": "Punho Duplo",
"magic_cost": "2x P.M",
"duration_time": null,
"attack_logic": null,
"action_type": "Aprimoramento",
"cast_distance": null,
"range_amount": null,
"range_type": null,
"icon": "GiDigHole",
"element": null,
"caption": "Você é o mestre dos Punhos de Mago, conseguindo desferir dois ataques poderosos simultaneamente.",
"description": "<p>Aprimora o Punhos de Mago, desferindo dois Punhos de Mago em uma única ação. Cada ataque precisa ser testado separadamente e precisa acertar o mesmo alvo.</p>",
"tags": ["grimo", "orbe-de-allura"]
}I'm not sure what would be the best place to start with this change? What do you suggest? Thanks for the help and for building a product so amazing! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
you don't need webpack or docosaurus plugin for this, i recommend to create spells.js file that imports all json files, with that source maps are going to point to actual files import apprentice_blast from './../../data/spells-allura/tier1/apprentice_blast.json'
export {
apprentice_blast: apprentice_blast,
// ....
}or export const apprentice_blast = require('./../../data/spells-allura/tier1/apprentice_blast.json')if you rly want to make this in automated way (not tested and most likely not fully working) const imports = require.context('./../../data/spells-allura/', true, /\.json$/);
const spells = imports.keys().reduce((key, acc) => {
acc[key] = imports(key);
return acc;
}, {});
export default spellswebpack/webpack#118 https://webpack.js.org/guides/dependency-management/#requirecontext |
Beta Was this translation helpful? Give feedback.
you don't need webpack or docosaurus plugin for this,
i recommend to create spells.js file that imports all json files, with that source maps are going to point to actual files
or
if you rly want to make this in automated way (not tested and most likely not fully working)