1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
| #!/bin/bash
# 1. 기본 디렉토리 생성
mkdir -p my-monorepo/apps/web my-monorepo/apps/admin my-monorepo/packages/shared my-monorepo/packages/tailwind-config
cd my-monorepo || exit
# 2. pnpm 설치 (이미 설치되어 있으면 생략)
if ! command -v pnpm &> /dev/null
then
echo "pnpm이 설치되지 않았습니다. 설치 중..."
npm install -g pnpm
fi
# 3. 루트 package.json 생성
cat <<EOT > package.json
{
"name": "my-monorepo",
"private": true,
"workspaces": {
"packages": ["apps/*", "packages/*"]
},
"scripts": {
"dev:web": "cd apps/web && pnpm dev",
"dev:admin": "cd apps/admin && pnpm dev",
"build:web": "cd apps/web && pnpm build",
"build:admin": "cd apps/admin && pnpm build"
}
}
EOT
# 4. pnpm-workspace.yaml 생성
cat <<EOT > pnpm-workspace.yaml
packages:
- 'apps/*'
- 'packages/*'
EOT
# 5. Tailwind 공통 설정
cat <<EOT > tailwind.config.js
module.exports = {
content: {
files: ['./apps/**/*.{js,jsx,ts,tsx}', './packages/**/*.{js,jsx,ts,tsx}'],
},
theme: {
extend: {},
},
plugins: [],
}
EOT
cat <<EOT > postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
EOT
# 6. Vite config (루트에 기본 vite.config.js)
cat <<EOT > vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
})
EOT
# 7. 공통 TypeScript 설정
cat <<EOT > tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"types": ["vite/client"],
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
},
"include": ["apps/**/*", "packages/**/*"],
"references": [
{ "path": "./apps/web/tsconfig.json" },
{ "path": "./apps/admin/tsconfig.json" },
{ "path": "./packages/shared/tsconfig.json" }
]
}
EOT
# 8. Shared 패키지 생성
cd packages/shared || exit
cat <<EOT > package.json
{
"name": "shared",
"version": "1.0.0",
"scripts": {
"build": "tsc"
},
"main": "dist/index.js",
"types": "dist/index.d.ts"
}
EOT
mkdir src
cat <<EOT > src/utils.ts
export function formatDate(date: Date): string {
return date.toLocaleDateString()
}
EOT
cat <<EOT > tsconfig.json
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"strict": true,
"declaration": true
},
"include": ["src"]
}
EOT
cd ../../..
# 9. Tailwind Config 패키지 생성
cd packages/tailwind-config || exit
cat <<EOT > package.json
{
"name": "tailwind-config",
"version": "1.0.0"
}
EOT
cat <<EOT > index.js
module.exports = {
content: {
files: [
'../../apps/**/*.{js,jsx,ts,tsx}',
'../../packages/**/*.{js,jsx,ts,tsx}'
]
},
theme: {
extend: {},
},
plugins: [],
}
EOT
cd ../../..
# 10. Web 앱 생성
cd apps/web || exit
pnpm create vite@latest . --template react
# Web 앱에 Tailwind 설치
pnpm add -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
cat <<EOT > tailwind.config.js
module.exports = {
presets: [require('../../tailwind.config')],
}
EOT
cat <<EOT > tsconfig.json
{
"compilerOptions": {
"baseUrl": "..",
"types": ["vite/client"]
},
"include": ["src"]
}
EOT
# Web 앱에서 shared 사용
cd ../../packages/shared
pnpm build
cd ../../apps/web
# Web 앱에 공유 패키지 링크
cd ../../apps/web
pnpm add ../shared
# Web 앱 App.tsx 수정
cd src
cat <<EOT > App.tsx
import React from 'react'
import { formatDate } from 'shared'
function App() {
return (
<div className="p-4 bg-blue-500 text-white">
Hello from Web App!
<p>{formatDate(new Date())}</p>
</div>
)
}
export default App
EOT
cd ../../apps/web
# Web 앱에 Tailwind 설정 반영
cat <<EOT > postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
EOT
# Tailwind CSS 추가
cat <<EOT > tailwind.config.js
module.exports = {
presets: [require('../../tailwind-config')]
}
EOT
# index.html에 Tailwind 적용
cd ../../apps/web
echo '<div id="root"></div>' > index.html
echo 'import React from "react";' > src/main.tsx
echo 'import ReactDOM from "react-dom/client";' >> src/main.tsx
echo 'import App from "./App";' >> src/main.tsx
echo 'ReactDOM.createRoot(document.getElementById("root")!).render(<App />);' >> src/main.tsx
# Web 앱에 TypeScript Path 설정
cd ../../apps/web
cat <<EOT > tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"types": ["vite/client"],
"paths": {
"@shared/*": ["../../packages/shared/src/*"]
}
},
"include": ["src"]
}
EOT
cd ../../..
# 11. Admin 앱 생성
cd apps/admin || exit
pnpm create vite@latest . --template react
# Admin 앱에 Tailwind 설치
pnpm add -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
cat <<EOT > tailwind.config.js
module.exports = {
presets: [require('../../tailwind.config')],
}
EOT
cat <<EOT > tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"types": ["vite/client"],
"paths": {
"@shared/*": ["../../packages/shared/src/*"]
}
},
"include": ["src"]
}
EOT
cd ../../apps/admin
pnpm add ../shared
cd ../../apps/admin/src
# Admin App.tsx 수정
cat <<EOT > App.tsx
import React from 'react'
import { formatDate } from 'shared'
function App() {
return (
<div className="p-4 bg-green-500 text-white">
Hello from Admin App!
<p>{formatDate(new Date())}</p>
</div>
)
}
export default App
EOT
cd ../../admin
# 12. 모든 작업 완료
cd ../../
echo "✅ Monorepo 생성 완료!"
echo "👉 다음 명령어로 개발 시작:"
echo "cd apps/web && pnpm dev"
echo "또는"
echo "cd apps/admin && pnpm dev"
|