|
1
|
import { Note } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `Install Medusa UI in Standalone Projects`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
In this guide, you'll learn how to install and use Medusa UI in a standalone project. |
|
10
|
|
|
11
|
Medusa UI is a React UI library that, while intended for use within Medusa projects, can also be used in any React project. |
|
12
|
|
|
13
|
<Note> |
|
14
|
|
|
15
|
The icons package is installed independently from Medusa UI. Learn how to install it in the [Icons](../../icons/overview/page.mdx) guide. |
|
16
|
|
|
17
|
</Note> |
|
18
|
|
|
19
|
--- |
|
20
|
|
|
21
|
## Medusa UI Compatibility |
|
22
|
|
|
23
|
To use Medusa UI in your standalone project, you must have: |
|
24
|
|
|
25
|
- React v18.3.1 or later (within the React 18 range) installed. The package's peer dependency requires `react@^18.3.1`, so React 19 is not officially supported yet. Most React 18-compatible frameworks and libraries, such as Next.js and Vite, satisfy this requirement. |
|
26
|
- [Tailwind CSS](https://v3.tailwindcss.com/) installed. The components in Medusa UI are styled using Tailwind CSS, so you'll need to install it in your project as well. |
|
27
|
- Medusa UI was built with Tailwind CSS v3, but it may also support v4. |
|
28
|
|
|
29
|
--- |
|
30
|
|
|
31
|
## Step 1: Install Medusa UI |
|
32
|
|
|
33
|
In your standalone project, install the Medusa UI package with the following command: |
|
34
|
|
|
35
|
```bash npm2yarn |
|
36
|
npm install @medusajs/ui |
|
37
|
``` |
|
38
|
|
|
39
|
--- |
|
40
|
|
|
41
|
## Step 2: Install UI Presets |
|
42
|
|
|
43
|
Medusa UI customizes Tailwind CSS classes to implement its design system, so you must also install the Medusa UI preset package. |
|
44
|
|
|
45
|
To install the Medusa UI preset, run the following command: |
|
46
|
|
|
47
|
```bash npm2yarn |
|
48
|
npm install @medusajs/ui-preset --save-dev |
|
49
|
``` |
|
50
|
|
|
51
|
--- |
|
52
|
|
|
53
|
## Step 3: Configure Tailwind CSS |
|
54
|
|
|
55
|
Next, you'll need to configure Tailwind CSS to use the Medusa UI preset and explicitly add the paths to the Medusa UI components as content files. |
|
56
|
|
|
57
|
### Tailwind CSS v3 Configurations |
|
58
|
|
|
59
|
In Tailwind CSS v3, which is the recommended version to use with Medusa UI, you need to add the following configurations to your `tailwind.config.js` or `tailwind.config.ts` file: |
|
60
|
|
|
61
|
1. Add the Medusa UI preset to the `presets` array. |
|
62
|
2. Ensure that the `content` field includes the path to the Medusa UI package. |
|
63
|
|
|
64
|
```js title="tailwind.config.js" highlights={[["5"]]} |
|
65
|
module.exports = { |
|
66
|
presets: [require("@medusajs/ui-preset")], |
|
67
|
content: [ |
|
68
|
// ... |
|
69
|
"./node_modules/@medusajs/ui/dist/**/*.{js,jsx,ts,tsx}", |
|
70
|
], |
|
71
|
// ... |
|
72
|
} |
|
73
|
``` |
|
74
|
|
|
75
|
If your project is in a monorepo, you'll need to resolve the path to the `@medusajs/ui` package from the monorepo root: |
|
76
|
|
|
77
|
export const monorepoHighlights = [ |
|
78
|
["3", "uiPath", "Resolve the UI package path from `node_modules`."], |
|
79
|
["13"] |
|
80
|
] |
|
81
|
|
|
82
|
```tsx title="tailwind.config.js" highlights={monorepoHighlights} |
|
83
|
const path = require("path") |
|
84
|
|
|
85
|
const uiPath = path.resolve( |
|
86
|
require.resolve("@medusajs/ui"), |
|
87
|
"../..", |
|
88
|
"\*_/_.{js,jsx,ts,tsx}" |
|
89
|
) |
|
90
|
|
|
91
|
module.exports = { |
|
92
|
presets: [require("@medusajs/ui-preset")], |
|
93
|
content: [ |
|
94
|
// ... |
|
95
|
uiPath, |
|
96
|
], |
|
97
|
// ... |
|
98
|
} |
|
99
|
|
|
100
|
``` |
|
101
|
|
|
102
|
### Tailwind CSS v4 Configurations |
|
103
|
|
|
104
|
Medusa UI isn't officially compatible with Tailwind CSS v4 yet, so use it with caution. |
|
105
|
|
|
106
|
In your CSS file that imports Tailwind CSS, add the following `@import`, `@config`, and `@source` directives: |
|
107
|
|
|
108
|
```css |
|
109
|
@import "tailwindcss"; |
|
110
|
@source "../node_modules/@medusajs/ui"; |
|
111
|
@config "@medusajs/ui-preset"; |
|
112
|
``` |
|
113
|
|
|
114
|
This will explicitly include the Medusa UI preset and its components in your Tailwind CSS build and apply the preset styles to your project. |
|
115
|
|
|
116
|
--- |
|
117
|
|
|
118
|
## Step 4: Use Medusa UI in Standalone Projects |
|
119
|
|
|
120
|
You can now start building your application with Medusa UI. |
|
121
|
|
|
122
|
For example, you can use the `Button` in your custom components: |
|
123
|
|
|
124
|
```tsx |
|
125
|
import { Button } from "@medusajs/ui" |
|
126
|
|
|
127
|
export function ButtonDemo() { |
|
128
|
return <Button>Button</Button> |
|
129
|
} |
|
130
|
``` |
|
131
|
|
|
132
|
Refer to the documentation of each component to learn about its props and usage. |
|
133
|
|
|
134
|
--- |
|
135
|
|
|
136
|
## Update UI Packages in Standalone Projects |
|
137
|
|
|
138
|
Medusa's design system packages, including `@medusajs/ui` and `@medusajs/ui-preset`, are versioned independently from other `@medusajs/*` packages. However, they're still released as part of Medusa's releases. |
|
139
|
|
|
140
|
So, to find the latest updates and breaking changes to any of these packages, refer to the [release notes in the Medusa GitHub repository](https://github.com/medusajs/medusa/releases). |
|
141
|
|
|
142
|
To update these packages in your standalone project, update their version in your `package.json` file and re-install dependencies. For example: |
|
143
|
|
|
144
|
```json title="package.json" |
|
145
|
{ |
|
146
|
"dependencies": { |
|
147
|
"@medusajs/ui": "4.0.0", |
|
148
|
"@medusajs/ui-preset": "4.0.0" |
|
149
|
} |
|
150
|
} |
|
151
|
``` |