themeteorchef / base

A starting point for Meteor apps.
http://themeteorchef.com/base
MIT License
689 stars 253 forks source link

When to use file extension on imports and when to use .jsx extension #220

Closed MarceloPrado closed 7 years ago

MarceloPrado commented 7 years ago

Hello, how are you doing today?

I'm developing a medium-large application and I've bootstrapped it with Base. I noticed that sometimes you've imported a file using its extension and sometimes you didn't. For example: import Component from '../components/Component and import Component from '../components/Component.js

What would be the appropriate way of doing this? I noticed that in some cases, React can't find the module without the extension.

Also, I noticed you're not using .jsx extension, but somehow it knows we're using React. How's that possible? I couldn't find any configuration file that setups this.

Thanks!

themeteorchef commented 7 years ago

Hi, Marcelo! I'm well; hope you are, too.

Re: .js vs .jsx, this is handled automatically via the Babel transpiler that Meteor uses behind the scenes as part of its build system. You can use either .jsx or .js for files containing JSX code and it will parse them properly either way (it can detect the JSX syntax).

In Base/my own projects, I prefer .js to keep all of my files consistent.

Going to close this out but feel free to add more questions/notes here :)