Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain what would happen if type is not json #6408

Open
adriancuadrado opened this issue Sep 19, 2022 · 4 comments
Open

Explain what would happen if type is not json #6408

adriancuadrado opened this issue Sep 19, 2022 · 4 comments

Comments

@adriancuadrado
Copy link

adriancuadrado commented Sep 19, 2022

In Rule.parser.parse, it says what would happen if you set Rule.type to json. What if Rule.type wasn't json? If this is only meant to be used when the type is json, wouldn't it make sense to assume the type is json by default? As described, this feature seems to only work with type json anyways. If you can specify anything else and not just json, would you mind to give examples?

@adriancuadrado
Copy link
Author

That section doesn't seem to describe the format of the input parameter. It's clear that it is a function that receives input and returns either a string or a json object. Is input an object? A string? if an object, which properties does it have? I'd bet it is the same input a loader would have as parameter, but it would be nice to state this explicitly.

@TheLarkInn
Copy link
Member

Looking at the type declarations you are right that this is very opaque. I believe input is designed to be a string type, but I'm not 100% sure without looking in the source code to verify. This would be really valuable to clarify in the documentation. Going to continue to search in code for an answer for you.

@TheLarkInn
Copy link
Member

Ah hah! Looks like I've found it here:

https://github.com/webpack/webpack/blob/dbf7bf39ab96e1462603435c150d601bb69ebe4e/lib/json/JsonParser.js#L26-L52

which led me to discover the JSON schema validation for this setting:

https://github.com/webpack/webpack/blob/dbf7bf39ab96e1462603435c150d601bb69ebe4e/schemas/plugins/JsonModulesPluginParser.json#L1-L12

So it looks like the point of this property is to provide a "mini transform function" like a loader which will take a string of the source which was detected, and then expect it to be in a JSON.parse-able formated object.

Would you be willing to commit back documentation for this @adriancuadrado

@adriancuadrado
Copy link
Author

@TheLarkInn I don't think I will. I would, but in order to improve this documentation to a point I'd feel comfortable, I think I'd need much more expertise in the subject than I have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants