Skip to content

Commit 5b9b278

Browse files
committed
Improve README
1 parent cc6e567 commit 5b9b278

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

.changeset/shaggy-spies-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro-auto-import': patch
3+
---
4+
5+
Improve README

packages/astro-auto-import/README.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,21 @@ An array of items that configure what files are imported and how.
7070
For Astro components or other files that have a default export, the easiest option is to provide their path and they will be imported with a name based on the file name.
7171

7272
```js
73-
imports: [
74-
'./src/components/A.astro',
75-
'./src/components/react/ReactComponent.tsx',
76-
];
73+
imports: ['./src/components/A.astro', './src/components/react/ReactComponent.tsx'];
7774
```
7875

79-
The above config would import `A` and `ReactComponent` respectively, so they could be used as `<A />` or `<ReactComponent />`.
76+
The above config will import `A` and `ReactComponent` respectively, so they could be used as `<A />` or `<ReactComponent />`.
77+
78+
###### Equivalent to
79+
80+
```js
81+
import A from './src/components/A.astro';
82+
import ReactComponent from './src/components/react/ReactComponent.tsx';
83+
```
8084

8185
##### Named exports
8286

83-
For script modules or component frameworks that can used named exports, you can pass an object mapping the module to the names you want to import.
87+
For script modules or component frameworks that can use named exports, you can pass an object mapping the module to the names you want to import.
8488

8589
```js
8690
imports: [
@@ -90,7 +94,13 @@ imports: [
9094
];
9195
```
9296

93-
This config would import both the `Twitter` and `YouTube` components from the `astro-embed` package.
97+
This config will import both the `Twitter` and `YouTube` components from the `astro-embed` package.
98+
99+
###### Equivalent to
100+
101+
```js
102+
import { Twitter, YouTube } from 'astro-embed';
103+
```
94104

95105
#### Import aliasing
96106

@@ -104,7 +114,33 @@ imports: [
104114
];
105115
```
106116

107-
This config would import the Astro component in `src/components/B.astro` but make it available as `<RenamedB />`.
117+
This config will import the Astro component in `src/components/B.astro` but make it available as `<RenamedB />`.
118+
119+
###### Equivalent to
120+
121+
```js
122+
import { default as RenamedB } from './src/components/B.astro';
123+
```
124+
125+
#### Namespace import
126+
127+
If you want to import all the named exports in a file to a namespace, you can pass a string to set the namespace to import to:
128+
129+
```js
130+
imports: [
131+
{
132+
'./src/components/index': 'Components',
133+
},
134+
];
135+
```
136+
137+
This config would import all the components in an index file, making them available as `<Components.A />`, `<Components.B />` etc.
138+
139+
###### Equivalent to
140+
141+
```js
142+
import * as Components from './src/components/index';
143+
```
108144

109145
## License
110146

0 commit comments

Comments
 (0)