I wanted to load some module type definitions in Monaco inside a react app for tutorial purposes.
I actually managed to get it working after much pain but in a very hacky way. So I'm not asking how to do it, but rather, how to do it right.
The part I hope I can solve with Webpack is that right now I made a Node.js script that take all the .d.ts file it can find in the build folder of a private npm module and save them inside a large .json file.
in this format
{ [filePath]: 'fileContentAsString' }
Then in react I import that json and call addExtraLib for each one.
for (const filePath in sdkTypesJson) {
// We add every .d.ts file to Monaco
monaco.languages.typescript.typescriptDefaults.addExtraLib(
sdkTypesJson[filePath],
'file:///' + filePath.replace('dist/src/', '')
);
}
Is there a way with some webpack magic to avoid having to create the json file?