この記事の最終更新日: 2023年4月16日
![React StoryBook TypeScript](https://i0.wp.com/yurupro.cloud/wp-content/uploads/2023/04/react_storybook_typescript.png?resize=1001%2C1000&ssl=1)
Setting up a React + TypeScript + Vite development environment in Docker and introducing Storybook
Initial directory structure
.
└ docker
| └ Dockerfile
└ docker-compose.yml
Dockerfile
FROM node:19.8.1
WORKDIR /data/src
RUN npm install -g npm@latest && npm install -g vite@latest
docker-compose.yml
version: '3'
services:
app:
build: ./docker
container_name: front
tty: true
volumes:
- ./src:/data
ports:
- "5173:5173"
- "6006:6006"
Creating a React+TypeScript project In the docker directory, run the following command:
$ docker-compose build
$ docker-compose run --rm app npm create vite@latest .
Press ‘y’ to select language and build settings, and the project will be created.
(base) react-ts % docker-compose run --rm app npm create vite@latest .
[+] Running 1/1
⠿ Network ln-sb_default Created 0.1s
Need to install the following packages:
create-vite@4.2.0
Ok to proceed? (y) y
✔ Select a framework: › React
✔ Select a variant: › TypeScript + SWC
Scaffolding project in /data/src...
Done. Now run:
npm install
npm run dev
(base) react-ts %
On the container, run npm install
Start the Docker container and enter the container.
Then, execute npm install, npm run build, and npm run dev.
$ docker-compose up -d
$ docker exec -it front sh
$ npm install
$ npm run build
$ npm run dev
The React + TypeScript + Vite project is now complete.
![React Vit TypeScript](https://i0.wp.com/yurupro.cloud/wp-content/uploads/2023/04/スクリーンショット-2023-04-06-11.43.12.png?resize=1024%2C519&ssl=1)
Introducing Storybook
Next, we’ll introduce Storybook.
$ docker-compose up -d
$ docker exec -it front sh
After starting the container, enter the command.
$ npx sb@latest init
Need to install the following packages:
sb@7.0.2
Ok to proceed? (y)
$ npm run storybook
If you see output like this, run npm run storybook.
(Note that after entering the command npx sb@latest init, it will take some time, so please wait for a while.)
![npx sb@latest init](https://i0.wp.com/yurupro.cloud/wp-content/uploads/2023/04/スクリーンショット-2023-04-05-2.49.22.png?resize=1024%2C684&ssl=1)
After the build is complete with npm run storybook, you will see output like this.
![ビルド完了](https://i0.wp.com/yurupro.cloud/wp-content/uploads/2023/04/スクリーンショット-2023-04-05-2.57.04.png?resize=1024%2C836&ssl=1)
Screen confirmation
![](https://i0.wp.com/yurupro.cloud/wp-content/uploads/2023/04/スクリーンショット-2023-04-05-2.57.44.png?resize=1024%2C525&ssl=1)
That’s it, the project creation is complete.
If you have any questions, please feel free to leave a comment.
![ゆるプロ日記](https://i0.wp.com/yurupro.cloud/wp-content/uploads/2023/01/12245_paint.png?resize=100%2C100&ssl=1)
大阪のエンジニアが書いているブログ。
コメント