Setting up a React + TypeScript + Vite development environment in Docker and introducing Storybook

React StoryBook TypeScript Docker
This article can be read in about 4 minutes.

この記事の最終更新日: 2023年4月16日

React StoryBook TypeScript

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.

http://localhost:5173/
React Vit TypeScript

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

After the build is complete with npm run storybook, you will see output like this.

ビルド完了

Screen confirmation

http://localhost:6006/?path=/docs/example-button–docs

That’s it, the project creation is complete.

If you have any questions, please feel free to leave a comment.

コメント

Copied title and URL