Create React AppのtemplateオプションにGitHub上のテンプレートを指定する
Create React App にはデフォルトで typescript のテンプレートがある。
npx create-react-app myapp --template typescript
この template オプションにはカスタムテンプレートを指定することができる。Custom Templates | Create React App
npm に公開されているテンプレートを指定する方法
Custom Templates | Create React Appを参照。
ローカルのテンプレートを指定する方法
これもCustom Templates | Create React Appに書いてある通りで
npx create-react-app myapp --template file:../path/to/your/template/cra-template-[template-name]
とする。
github上のリポジトリに置いたテンプレートを指定する方法
これが本題。Create React App の template オプションには github のリポジトリに置いたテンプレートを直接指定できる。npm に公開する必要はない(Create React App version 4.00 で確認済み)。以下のように指定する。
npx create-react-app myapp --template git+https://github.com/account/cra-template-my-template-name.git
npm に公開されていない github 上のパッケージは npm install git+https://github.com/account/my-package.git
でインストールすることができる。Create React App は template オプションで指定した文字列を単純に npm install しているようである。そのため --template
の後ろに --template git+https://github.com/account/my-package.git
とつなげることで github 上のテンプレートを指定することができる。あとはこれの応用でブランチの指定やタグなどを指定できるかもしれない。