Hello everyone, at the beginning of the year, I wish you a new year full of health, happiness with your family and working effectively, reaping many successes in life.
Introduce
In normal Javascript projects, where do you usually use and import?
There are 3 neat import tips
1. Barrel Pattern is the grouping of many individual components (A, B, C, D, …) in a single file One, so just import to file One and then call other components to use it.
- Create an index.js file in the columns . folder
- Using componenet in other files
So with only a single composite file, files using components can be imported more succinctly. Using aliases As shown at the beginning of the article, after each word, there are many punctuation marks. and the / looks very confusing. Like v, you need to set up alias, alias has the following benefits: - shorten each import line
- when importing in different files but the string after from is unchanged Download this package to npm i babel-plugin-module-resolver or yarn add babel-plugin-module-resolver. There are 2 types without using Typscript and using Typescript Without using Typescript Create file babel.config.js and add these lines
Using Typescript Use the library Prettier plugin sort imports: https://github.com/trivago/prettier-plugin-sort-imports It will transfer: Wall
With the above 3 tips, your import lines will become much more beautiful and compact. And finally, I wish you all a very successful new year.