-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Warn about JSX file extension #290
Comments
I'd like to work on this. I imagine the best way would be to publish a webpack plugin that takes some regex and error message as options to keep it configurable and potentially useful in other contexts. Does that approach make sense? |
Sounds reasonable. |
I fix it~ |
Submitted #353 |
@stephenkingsley Since @tizmagik first offered to work on this, let’s give him the opportunity to finish it? @tizmagik I think it’s not just importing |
I review @tizmagik code. when the webpack compile |
I want the following to work:
|
thx! I think @tizmagik is work too easy to fix this problem. |
If have a solution that both have |
I’m not sure I understand what you’re asking. |
Sorry, my english is not good. User writes |
checking the file that webpack compiling whether is the jsx file. I do not know what's wrong? and I think this is done what your want. |
compiler.plugin('normal-module-factory', function (nmf) {
nmf.plugin('after-resolve', function (data, done) {
var pathName = data.resource.split('?')[0];
if (pathName.match(/\/[A-Za-z0-9]+\.jsx$/)) {
done(new Error('do not require .jsx file in ', pathName));
} else {
done(null, data);
}
});
}); this is my idea, I need your suggestion. please help me. |
@gaearon thanks for reviewing my PR. I think the way this is currently written is the cleanest/most correct way. That is, because of these lines in resolve: {
extensions: ['', '.js', '.json'],
// ...
} If a user just does
Since So, instead, this plugin guards against a user specifying the If, however, you want webpack to auto-resolve the .JSX extension, then you can add Does that make sense? |
I understand, and this is exactly the problem I want to solve with this issue. My proposal is a resolve plugin that checks if a |
hahaha, I exactly knew what your means! |
In that case, I wonder if it's any more or less correct to add ".jsx" to resolve.extensions[] and then have this plugin warn about using JSX files? I think it would achieve the same result. Curious to hear your thoughts... |
Yeah, I guess this would technically work. |
Alright, in that case, I'll push up a new commit to add ".jsx" to |
I left it out of the prod webpack config, which I think makes sense. #361 ready for review. Thanks. |
Just a question. Why all the fuzz about .jsx. Isn't it the desired extension when working with JSX? I was wondering why create-react-app uses the .js file extension for all files even if the file contains JSX. I'm just curious, thanks in advance for any explanation. 😃 Found my answer here: #87 (comment) |
I think that if people only use "JSX" theme in component files, they miss out on all the ES6 + beyond highlighting that "Babel" themes (often marketed as JSX) usually implement. Ideally we should just include proper instructions on installing a Babel syntax theme. |
I’ll get back to it as soon as I’m done with other things. 😉 |
I use jsx extension because my editor( VS Code) support Emmet only for jsx files. |
If there is no support for jsx, also all typescript users are not in play as TS compiles TSX to JSX :/ It would be great to have the possibility to set the resolve. extensions bit. |
Having had a similar discussion on
Therefore, my proposed solution would be:
PS: this is coming from someone who has had to learn react from scratch in the last month and use it to inceptualize a large project's codebase |
Okay, let’s add support for |
We support JSX extension since 0.4.1 even though we don’t recommend it. |
Update
We support JSX extension since 0.4.1 even though we don’t recommend it.
Read the release notes.
Original Thread
We don’t support it. AFAIK there is no good reason to: #87 (comment).
We should do two things:
The text was updated successfully, but these errors were encountered: