You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add note for how to specify subpath import regex to README (#243)
Figured this should go with the existing local alias examples, it's a
simpler approach, and presumably the new state-of-art for local aliases,
so maybe it should go higher in the examples?
Followup to #242
---------
Co-authored-by: Ian VanSchooten <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+24-4Lines changed: 24 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,9 +297,29 @@ import { createBrowserHistory } from 'history';
297
297
importAppfrom'./App';
298
298
```
299
299
300
-
##### 5. Group aliases with local imports
300
+
##### 5. Group subpath import style local aliases
301
301
302
-
If you define non-relative aliases to refer to local files without long chains of `"../../../"`, you can include those aliases in your `importOrder` to keep them grouped with your local code.
302
+
If you are using [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) (local imports starting with "#"), you can include those in your `importOrder` to keep them grouped with your local code, perhaps just above your relative imports, as shown below.
303
+
304
+
```json
305
+
"importOrder": [
306
+
"<THIRD_PARTY_MODULES>",
307
+
"^#.+",
308
+
"^[.]"]
309
+
```
310
+
311
+
e.g.:
312
+
313
+
```ts
314
+
import { debounce, reduce } from'lodash';
315
+
import { Users } from'#api';
316
+
importiconfrom'#assets/icon';
317
+
importAppfrom'./App';
318
+
```
319
+
320
+
##### 6. Group aliases with local imports
321
+
322
+
If you use some other method to define non-relative aliases to refer to local files without long chains of `"../../../"`, you can include those aliases in your `importOrder` to keep them grouped with your local code. If you use the common `@` symbol for these aliases, you may want some way to group them separately from scoped npm packages, which can be done like this:
303
323
304
324
```json
305
325
"importOrder": [
@@ -317,7 +337,7 @@ import icon from '@assets/icon';
317
337
importAppfrom'./App';
318
338
```
319
339
320
-
##### 6. Enforce a blank line after top of file comments
340
+
##### 7. Enforce a blank line after top of file comments
321
341
322
342
If you have pragma-comments at the top of file, or you have boilerplate copyright announcements, you may be interested in separating that content from your code imports, you can add that separator first.
323
343
@@ -341,7 +361,7 @@ import icon from '@assets/icon';
341
361
importAppfrom'./App';
342
362
```
343
363
344
-
##### 7. Enable/disable plugin or use different order in certain folders or files
364
+
##### 8. Enable/disable plugin or use different order in certain folders or files
345
365
346
366
If you'd like to sort the imports only in a specific set of files or directories, you can disable the plugin by setting `importOrder` to an empty array, and then use Prettier's [Configuration Overrides](https://prettier.io/docs/en/configuration#configuration-overrides) to set the order for files matching a glob pattern.
0 commit comments