Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig alias-support-documentation (PR from TinaCMS) #2647

Merged
merged 10 commits into from
Dec 29, 2024
34 changes: 34 additions & 0 deletions content/docs/reference/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,37 @@ export default defineConfig({

In this example, the TinaCMS admin will be viewable at `<my-site-url>/admin/index.html`.
For more information [check out the content modeling section](/docs/schema/).


## Typescript Path Alias

TinaCMS supports TypeScript path aliases in the `tina/config.{ts,js,tsx}` file and collections, making it easier to organize and maintain your code.

##### Use alias in tina/config.{ts,js,tsx}

Ensure that `tsconfig.json` exists at the root of your project. Define your aliases in the `compilerOptions` section:

```json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
```

Figure: Your defined `tsconfig.json`

You can now import utilities or other modules using the aliases:

```typescript
import { someUtility } from '@/lib/utils';

export default defineConfig({
....
})
```

Figure: Using aliases in tina `tina/config.{ts,js,tsx}`
Ben0189 marked this conversation as resolved.
Show resolved Hide resolved
Loading