In the Docker environment (I haven't checked other environments), when you do gatsby new
orgatsby new ~
, ** npm installation ** will be done without any questions.
Here's how to use yarn
to gats by new
!
project-name
|- .config
|- gatsby
|- config.json
|-Generated gatsby files
|- ...
|- docker-compose.yml
|- Dockerfile
Prepare in advance other than the generated gatsby files described above.
This is the way to use yarn. ↓ See here for details ↓ Using Yarn as your Gatsby package manager
Create config.json
according to the previous configuration, and write the following with reference to the official document.
config.json
{
"cli": {
"packageManager": "yarn"
}
}
The configuration is as follows to connect the settings of config.json
with the settings in the container.
Dockerfile
FROM node:12.17.0
RUN mkdir project-name
WORKDIR /project-name
COPY .config /root/.config/
RUN yarn global add gatsby-cli
Then it becomes the docker-compose
file
docker-compose.yml
version: '3.8'
services:
gatsby:
build: ./
tty: true
stdin_open: true
volumes:
- ./:/project-name
environment:
- NODE_ENV=development
ports:
- 8000:8000
- 9000:9000
Create an image, start the container, and go inside the container.
$ docker-compose build
$ docker-compose up -d
$ docker-compose exec gatsby bash
Let's go see if the file exists in the container once!
$ cat /root/.config/gatsby/config.json
If you have the config.json
you created earlier, you're successful!
Then try gats by new ~
!
$gatsby new Folder name of the generated gatsby files
** It should have been created by yarn
! !! ** **
I've been searching for various articles and looking for a way to create them with just yarn, and I found one, so I shared it!
Note that the config.json
file contains values that I didn't understand well, so it may be better to ignore the main body when pushing and create config.example.json
etc. Hmm.
Recommended Posts