1

I'm working on writing a loader for filename.xyz.json files.

Now since Webpack version 2, Webpack support loading JSON files out of the box. So I've managed to get my loader to work when working when using a completely custom file extension like .xyz.jayson.

But because I'm using .json the other, already existing loader gets triggered after my loader did his magic, which will cause an error because at this point it's not JSON anymore. How can I prevent that?

If I understand the Webpack docs correctly, the !! prefix with inline usage would do just that. But I would like to disable post/pre loaders in the config. Is this possible?

Also, I was thinking of actually using that given JSON loader instead of dodging it, because why parse the JSON myself, when there is already a loader for it? But I don't quite sure if that is possible since the returned source from the JSON is already returned as module.export. Would I need to strip the module.export and then run JSON.parse to work with it as an actual js object instead of a string?

So as a quick summary:

I'd like to either to not trigger the JSON loader at all, and parse the JSON myself to manipulate it or use the built-in JSON loader first and then manipulate the JSON data file myself.

josias
  • 1,326
  • 1
  • 12
  • 39

1 Answers1

0

I found the solution:

Setting the type of my rule to javascript/auto gave me the expected result.

More information here

josias
  • 1,326
  • 1
  • 12
  • 39