I'm importing some resources in my Vue file. The fact that it's Vue, though, have nothing to do with my question, I believe.
I import them as such:
import Vue from 'vue'
import { mapState, mapMutations } from 'vuex'
import ChessPiece from '../assets/classes/chesspiece'
import 'vue-awesome/icons/rotate-left'
import 'vue-awesome/icons/search'
ESLint then tells me:
Absolute imports should come before relative imports
I'm just wondering, why is this?
Remember that you should generally opt for absolute imports over relative ones, unless the path is complex and would make the statement too long.
Using absolute imports to better organize your React project is a great way. Relative imports are hard to follow and break during refactoring. Absolute imports manage your project easier as it grows. Forget long relative imports after this article. This is my 40th Medium article.
Relative imports use dot(.) notation to specify a location. A single dot specifies that the module is in the current directory, two dots indicate that the module is in its parent directory of the current location and three dots indicate that it is in the grandparent directory and so on.
Because there, they want to make sure that other developers could also get the full path of the import module. Relative imports are helpful when you are working alone on a Python project, or the module is in the same directory where you are importing the module.
It's just an coding convention to make everything cleaner.
Usually absolute imports comes from external library, and relative imports from your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With