Created
July 9, 2025 18:50
-
-
Save adityawasudeo/3ba442a36ef90202312e04cbc1943da2 to your computer and use it in GitHub Desktop.
Running Vite + TS React in a dev container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
init: | |
profiles: ["init"] | |
build: | |
context: app | |
target: init | |
volumes: | |
- ./app:/app | |
- /app/node_modules | |
command: > | |
sh -c " | |
if [ ! -f vite.config.ts ]; then | |
echo 'Creating new Vite React+TypeScript project...' | |
npm create vite@latest . -- --template react-ts | |
else | |
echo 'Project already exists. Skipping creation.' | |
fi | |
" | |
dev: | |
profiles: ["dev"] | |
env_file: | |
- .env.dev | |
ports: | |
- "5173:5173" | |
build: | |
context: app | |
target: dev | |
volumes: | |
- ./app:/app | |
- /app/node_modules | |
stdin_open: true | |
tty: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:20-alpine AS init | |
RUN mkdir /app | |
WORKDIR /app | |
COPY package.json ./ | |
COPY . . | |
FROM node:20-alpine AS dev | |
RUN mkdir /app | |
WORKDIR /app | |
COPY package.json ./ | |
RUN npm install | |
RUN npm ci | |
CMD ["npm", "run", "dev"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Create a directory called /app | |
2. Build the environment: | |
`docker compose run --rm init` | |
3. Run the container: | |
`docker compose up dev` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment