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
37 changes: 36 additions & 1 deletion content/docs/reference/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,39 @@ 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/).
For more information [check out the content modeling section](/docs/schema/).\
\
Ben0189 marked this conversation as resolved.
Show resolved Hide resolved


## Typescript Path Alias

TinaCMS supports typeScript path aliases in the tina.config.js file and collections, making it easier to organize and maintain your code.
Ben0189 marked this conversation as resolved.
Show resolved Hide resolved

##### Use alias in config.ts

Ensure that tsconfig.json exists at the root of your project. Define your aliases in the compilerOptions section:
Ben0189 marked this conversation as resolved.
Show resolved Hide resolved

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

Figure: Your defined tsconfig.json
Ben0189 marked this conversation as resolved.
Show resolved Hide resolved

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 config.ts
Ben0189 marked this conversation as resolved.
Show resolved Hide resolved
Loading