#!/bin/zsh if [ $# -eq 0 ] ; then echo "Pass the name of project" exit 1 fi yarn set version berry NAME="$1" yarn dlx create-react-app $NAME --template typescript cd $NAME yarn dlx @yarnpkg/pnpify --sdk vscode TO_DECLARE="declare module '@testing-library/react';" printf $TO_DECLARE >> src/react-app-env.d.ts code .The above is same as https://www.anicehumble.com/2020/08/create-react-app-with-typescript-and-pnp.html
The previous one does not create hidden directory(.yarn) and file (.yarnrc.yml) on the parent directory of the project, while the script above do.
The advantage of the script above is almost everything works out of the box, but you just have to tolerate the creation of .yarn directory and .yarnrc.yml file on the directory where you run the create-react-app
Looks like it is safe to run "yarn set version berry" once on the home directory if you don't have any project that is dependent on yarn version 1. Setting yarn to berry on home folder would make yarn use the version 2 globally. With that said, the "yarn set version berry" above can be removed from the script.
If you set the yarn to version 2 globally and you need to go back to version 1, just delete the .yarn directory and .yarnrc file, yarn will run as version 1 again.
No comments:
Post a Comment