Skip to content

Commit 93ba858

Browse files
committed
docs: add section on type aliases in admin + note for removing items from orders
1 parent 9c94580 commit 93ba858

File tree

6 files changed

+277
-30
lines changed

6 files changed

+277
-30
lines changed

www/apps/api-reference/specs/admin/openapi.full.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23266,7 +23266,9 @@ paths:
2326623266
operationId: PostOrderEditsIdItemsItemItem_id
2326723267
summary: Update Order Item Quantity of Order Edit
2326823268
x-sidebar-summary: Update Item Quantity
23269-
description: Update an existing order item's quantity of an order edit.
23269+
description: |
23270+
Update an existing order item's quantity of an order edit.
23271+
You can also use this API route to remove an item from an order by setting its quantity to `0`.
2327023272
x-authenticated: true
2327123273
parameters:
2327223274
- name: id

www/apps/api-reference/specs/admin/paths/admin_order-edits_{id}_items_item_{item_id}.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ post:
22
operationId: PostOrderEditsIdItemsItemItem_id
33
summary: Update Order Item Quantity of Order Edit
44
x-sidebar-summary: Update Item Quantity
5-
description: Update an existing order item's quantity of an order edit.
5+
description: >
6+
Update an existing order item's quantity of an order edit.
7+
8+
You can also use this API route to remove an item from an order by setting
9+
its quantity to `0`.
610
x-authenticated: true
711
parameters:
812
- name: id

www/apps/book/app/learn/configurations/ts-aliases/page.mdx

Lines changed: 125 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,30 @@ export const metadata = {
44

55
# {metadata.title}
66

7-
By default, Medusa doesn't support TypeScript aliases in production.
7+
In this chapter, you'll learn how to use TypeScript aliases in your Medusa application.
88

9-
If you prefer using TypeScript aliases, install following development dependencies:
9+
## Support for TypeScript Aliases
10+
11+
By default, Medusa doesn't support TypeScript aliases in production. That means you may get build errors in production if you use them in your development.
12+
13+
If you prefer using TypeScript aliases, this section will guide you through the steps to enable them in your Medusa application.
14+
15+
### Step 1: Install Required Dependencies
16+
17+
Start by installing the following development dependencies:
1018

1119
```bash npm2yarn
1220
npm install --save-dev tsc-alias rimraf
1321
```
1422

15-
Where `tsc-alias` is a package that resolves TypeScript aliases, and `rimraf` is a package that removes files and directories.
23+
Where:
1624

17-
Then, add a new `resolve:aliases` script to your `package.json` and update the `build` script:
25+
- `tsc-alias` resolves TypeScript aliases.
26+
- `rimraf` removes files and directories.
27+
28+
### Step 2: Update `package.json`
29+
30+
Then, add a new `resolve:aliases` script to your `package.json` and update the existing `build` script:
1831

1932
```json title="package.json"
2033
{
@@ -26,7 +39,11 @@ Then, add a new `resolve:aliases` script to your `package.json` and update the `
2639
}
2740
```
2841

29-
You can now use TypeScript aliases in your Medusa application. For example, add the following in `tsconfig.json`:
42+
### Step 3: Update `tsconfig.json`
43+
44+
Next, configure the TypeScript aliases you want to use in your `tsconfig.json` file by adding a `paths` property under `compilerOptions`.
45+
46+
For example, to import anything under the `src` directory using type aliases, add the following in `tsconfig.json`:
3047

3148
```json title="tsconfig.json"
3249
{
@@ -39,8 +56,110 @@ You can now use TypeScript aliases in your Medusa application. For example, add
3956
}
4057
```
4158

42-
Now, you can import modules, for example, using TypeScript aliases:
59+
### Step 4: Use TypeScript Aliases
60+
61+
Then, you can use the `@` alias in your application code.
62+
63+
For example, if you have a service in `src/modules/brand/service.ts`, you can import it like this:
4364

4465
```ts
4566
import { BrandModuleService } from "@/modules/brand/service"
4667
```
68+
69+
---
70+
71+
## Support TypeScript Aliases for Admin Customizations
72+
73+
Medusa also doesn't support TypeScript aliases in the admin customizations by default. However, you can also configure your Medusa application to use TypeScript aliases in your admin customizations.
74+
75+
### Step 1: Update `src/admin/tsconfig.json`
76+
77+
Update `src/admin/tsconfig.json` to include `baseUrl` and `paths` configuration:
78+
79+
```json title="src/admin/tsconfig.json"
80+
{
81+
"compilerOptions": {
82+
"baseUrl": ".",
83+
"paths": {
84+
"@/*": ["./*"]
85+
}
86+
87+
// other options...
88+
}
89+
}
90+
```
91+
92+
The `baseUrl` option sets the base directory to `src/admin`, and the `paths` option defines the `@` alias to allow importing files from the `src/admin` directory using aliases.
93+
94+
### Step 2: Update `medusa-config.ts`
95+
96+
Next, update the `vite` configuration in `medusa-config.ts` to include the `resolve.alias` configuration:
97+
98+
```ts title="medusa-config.ts"
99+
import path from 'path'
100+
101+
module.exports = defineConfig({
102+
// ...
103+
admin: {
104+
vite: () => ({
105+
resolve: {
106+
alias: {
107+
"@": path.resolve(__dirname, "./src/admin"),
108+
},
109+
},
110+
}),
111+
},
112+
})
113+
```
114+
115+
<Note title="Tip">
116+
117+
Learn more about the `vite` configuration in the [Medusa configuration](../medusa-config/page.mdx) chapter.
118+
119+
</Note>
120+
121+
### Step 3: Use TypeScript Aliases in Admin Customizations
122+
123+
You can now use the `@` alias in your admin customizations, just like you do in your main application code.
124+
125+
For example, if you have a component in `src/admin/components/Container.tsx`, you can import it in a widget like this:
126+
127+
```ts
128+
import Container from "@/components/Container"
129+
```
130+
131+
### Match TSConfig and Vite Alias Configuration
132+
133+
Make sure that the `@` alias points to the same path as in your `src/admin/tsconfig.json`.
134+
135+
For example, if you set the `@/*` alias to point to `./components/*`:
136+
137+
```json title="src/admin/tsconfig.json"
138+
{
139+
"compilerOptions": {
140+
"baseUrl": ".",
141+
"paths": {
142+
"@/*": ["./components/*"]
143+
}
144+
}
145+
}
146+
```
147+
148+
Then, the `vite` alias configuration would be:
149+
150+
```ts title="medusa-config.ts"
151+
import path from 'path'
152+
153+
module.exports = defineConfig({
154+
// ...
155+
admin: {
156+
vite: () => ({
157+
resolve: {
158+
alias: {
159+
"@": path.resolve(__dirname, "./src/admin/components"),
160+
},
161+
},
162+
}),
163+
},
164+
})
165+
```

www/apps/book/generated/edit-dates.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const generatedEditDates = {
112112
"app/learn/resources/contribution-guidelines/docs/page.mdx": "2025-05-26T15:55:02.974Z",
113113
"app/learn/resources/usage/page.mdx": "2025-02-26T13:35:34.824Z",
114114
"app/learn/configurations/medusa-config/page.mdx": "2025-07-14T09:28:54.302Z",
115-
"app/learn/configurations/ts-aliases/page.mdx": "2025-02-11T16:57:46.683Z",
115+
"app/learn/configurations/ts-aliases/page.mdx": "2025-07-18T15:06:59.037Z",
116116
"app/learn/production/worker-mode/page.mdx": "2025-03-11T15:21:50.906Z",
117117
"app/learn/fundamentals/module-links/read-only/page.mdx": "2025-05-13T15:04:12.107Z",
118118
"app/learn/fundamentals/data-models/properties/page.mdx": "2025-03-18T07:57:17.826Z",

0 commit comments

Comments
 (0)