Giter VIP home page Giter VIP logo

Comments (5)

alan2207 avatar alan2207 commented on August 15, 2024 2

It works well with VSCode, you should definitely give it a shot.

And if you have the import/order enabled in eslint you will get a nice visual separation of local vs dependency modules which you do not get with the suggested approach.

Screenshot 2022-01-11 at 09 32 30

(ignore the squiggly line in the left image for now), VSCode did linting auto fix on save automatically and reordered the imports.

from bulletproof-react.

alan2207 avatar alan2207 commented on August 15, 2024 1

Hi there,

Both of your suggestions are valid. I wrote a bit here about the reason why I am choosing this way:

"It is also possible to define multiple paths for various folders(such as @components, @hooks, etc.), but using @/* works very well because it is short enough so there is no need to configure multiple paths and it differs from other dependency modules so there is no confusion in what comes from node_modules and what is our source folder. That means that anything in the src folder can be accessed via @, e.g some file that lives in src/components/MyComponent can be accessed using @/components/MyComponents."

In a nutshell, I find it useful to have a symbol in front of it because it will prevent conflicts from node_modules imports in case a folder in src has the same name as some dependency - happens not very often, but it's nice to be sure and not to think about it ever again. In the end, it's just a matter of preference :)

from bulletproof-react.

romeerez avatar romeerez commented on August 15, 2024

it's just the same with a different symbol, while I was suggesting to mention that baseUrl exists and seems to be a valid option, and either relative imports is not a big deal with modern editors

from bulletproof-react.

romeerez avatar romeerez commented on August 15, 2024

Chance there is an overlap with npm module is very close to zero, so it will never happen in of 99.99% cases, if happen it can be workarounded by aliasing module, and import { X } from 'components/X' is more pleasant import to read, so I think it worth to mention this in same document. All other suggestions are very good to be picked by default, and @/ stands out here in my opinion as imperfect default

so there is no confusion in what comes from node_modules and what is our source folder.

yes, it mentioned that it's possible to do in a "confusing" way, but many people reading this don't know it's even possible and how to setup it in this way, so they cannot prefer one way over another and decide if "components/X" is confusing or not on they own

from bulletproof-react.

romeerez avatar romeerez commented on August 15, 2024

I understand why better to have zero chance than close to zero, and if you're sure @/ is a better practice let's close this issue

I never tried @/ myself so unsure if it's easy to configure popular editors VSCode and JetBrains to use it in autocompletion, assuming it's easy, since no info about it in the doc

from bulletproof-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.