Skip to content

Commit 2303b49

Browse files
authored
Add baseUrl documentation (#6847)
* Add baseUrl documentation * Update docusaurus/docs/importing-a-component.md Co-Authored-By: ianschmitz <ianschmitz@gmail.com> * Update docusaurus/docs/importing-a-component.md Co-Authored-By: ianschmitz <ianschmitz@gmail.com> * Simplify include to match default tsconfig.json
1 parent 200b98b commit 2303b49

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docusaurus/docs/importing-a-component.md

+25
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,28 @@ Learn more about ES6 modules:
4848
- [When to use the curly braces?](https://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281)
4949
- [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
5050
- [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
51+
52+
## Absolute Imports
53+
54+
You can configure your application to support importing modules using absolute paths. This can be done by configuring a `jsconfig.json` or `tsconfig.json` file in the root of your project. If you're using TypeScript in your project, you will already have a `tsconfig.json` file.
55+
56+
Below is an example `jsconfig.json` file for a JavaScript project. You can create the file if it doesn't already exist:
57+
58+
```json
59+
{
60+
"compilerOptions": {
61+
"baseUrl": "src"
62+
},
63+
"include": ["src"]
64+
}
65+
```
66+
67+
If you're using TypeScript, you can configure the `baseUrl` setting inside the `compilerOptions` of your project's `tsconfig.json` file.
68+
69+
Now that you've configured your project to support absolute imports, if you want to import a module located at `src/components/Button.js`, you can import the module like so:
70+
71+
```js
72+
import Button from 'components/Button';
73+
```
74+
75+
For more information on these configuration files, see the [jsconfig.json reference](https://code.visualstudio.com/docs/languages/jsconfig) and [tsconfig.json reference](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) documentation.

0 commit comments

Comments
 (0)