-
Notifications
You must be signed in to change notification settings - Fork 82
Please add a link for "Don't forget to polyfill require" #7
Comments
I agree. Related issue: webpack/webpack#140 |
+1. I have no idea how to use Update Okay, it looks like I need to do this:
|
This doesn't seem to work when I use |
@donaldpipowitch requir calls with magic names (ie only having some meaning at runtime) will always be a problem because the bundler has no idea what you're asking for (it would have to actually run the code to figure out which thing you're actually requiring) so you're going to have to use relative, explicit strings like |
I don't want to bundle my JSON file in that case. I want a vanilla Node require. Webpack should do nothing. (I have a hack in webpack/webpack#2413 which works.) |
if it's code that will end up in your bundle, there is no vanilla node, because the bundle will run in the browser. Unless your webpack config is set to target node, specifically (in which case bundling is arguably a bad idea, just rely on npm). However, if it's code that never ends up even being bundled in, then you don't need a webpack loader; node already knows how to require .json files |
As mentioned above it is
That is exactly what I meant with Nodes "vanilla require". I use webpack just for other things then JSON. |
in that case I don't quite understand why you're commenting on a thread that is specifically about webpack's json-loader, which is necessary only when you need to bundle. If your |
Sorry, I don't know if you read my comments. In my first commend I said "I don't know if json-loader helps me here?". So yes, maybe this was the wrong issue in the first place but nobody corrected me, so I thought I was correct. That was nearly a month ago. Now I know json-loader was the wrong tool for my problem. I DID created a new issue in a different repository. I just commented here for people who look at this loader for the same problem in the first place - just like me. I don't even use json-loader. But if you ask someone how to load JSON in a webpack based Node project, everyone seems to redirect you to this repository as the only valid solution... You even said "this statement is absolutely not what someone who's looking for information on why loading json isn't working hopes to find." This is what drove me here, too. Loading JSON in a Node project wasn't working for me. However this README doesn't tell what this loader really does (or not does which was more important for me as it turns out). It just says "don't forget the require polyfill". Browsers don't have a |
Fair enough, but this is the Webpack, like all bundlers, absolutely rewrites |
As an alternative to using a |
I do use webpack to bundle code, but this doesn't mean that I want to bundle my JSON, because it isn't static. I just wanted clarify that. It is not either bundling and using webpack or not bundling and don't use webpack. You can use webpack for bundling most things (like your code), but not everything (like some JSON). And it is quite hard to figure out how to opt-out from bundling in some cases. @rob3c Thanks, I'll look into that. |
I would like to vote to remove the statement entirely, instead of adding a link, because this sentence makes it seem that if I do want to bundle the JSON with my generated library, then I need to do some additional work in order to make it function in Node environments—which does not seem to be the case. In webpack/webpack#140 @sokra goes so far as to state "The sentence is pretty old, I should remove it from all the loaders.", indicating this is a legacy of an earlier time. |
@kadamwhite thanks for your insights. I've removed the statement. |
This statement is absolutely not what someone who's looking for information on why loading json isn't working hopes to find. It just makes them more angry because no one's explaining how the hell to use this loader =)
The text was updated successfully, but these errors were encountered: