meteor / todos

The example app "Todos", written following the Meteor Guide
Other
535 stars 367 forks source link

Absolute VS Relative Paths (Imports) #205

Closed jdnichollsc closed 6 years ago

jdnichollsc commented 7 years ago

Hi guys,

One question, what is better?

or

import { updateName } from '/imports/api/lists/methods.js';

Thanks for this excellent example! I've created a blank template too (Based on this template, I need to update the documentation)

Regards, Nicholls

alexpricedev commented 7 years ago

I choose based on context. In React components I usually use relative paths as components can be moved around and between projects etc. I like to use absolute paths for helpers etc as the absolute path always works if i need to refactor or move files around :)

abernix commented 6 years ago

There isn't really a right answer here. Whatever makes more sense for your project! Some things which are more top-level might be moved around less frequently, whereas components in a complicated tree might be moved around regularly.

yashrahurikar23 commented 4 years ago

It all depends on your project requirement, Projects folder structure is complex and deep use absolute imports, folder structure is comparatively simple use relative imports. Wish to improve code readability use relative imports otherwise use absolute imports. JS community usually use relative imports in libraries but as I said it all depends on your requirement.

Still if you want a solid answer, Airbnb style guide say that if your dependencies are less than two level deep use relative imports, whereas, if your dependencies are more than two level deep use absolute imports. Please find a link to such discussion: https://docs.gitlab.com/ee/development/new_fe_guide/style/javascript.html