Reactのアプリの雛形を作成するコマンドといえば
npx create-react-app my-app
に馴染みがあるのではないでしょうか。
私も特に疑問も持たずに、これまでこのコマンドでアプリを生成してきました。
しかし、これだと開発を進めていく際にyarn
コマンドでパッケージの追加を使うとpackage-lock.json
とyarn.lock
がどちらもある状態になってしまい気持ち悪いことになります。
一旦、package-lock.json
とnode_modulesディレクトリ
を削除して、yarn install
で入れ直すことで解決できますが、それも二度手間。できれば気持ちよくReactの開発をスタートさせたいものです。
では、「yarnでcreate-react-appする」にはどうすればいいのか?
Yarnでcreate React Appする
それが、こちら。
yarn create react-app my-app
このコマンドを実行することでmy-appというプロジェクトが作成されます。
npx
の時はcreate-react-appでしたが、yarn
の場合はcreate react-appとなっている点に注意です。
また、typescriptで構築したい場合は
yarn create react-app my-app --template typescript
とすればOK。
これで気兼ねなくyarn add
でバンバンnodeパッケージをインストールしたり削除したりできます笑
参考
https://create-react-app.dev/docs/getting-started/#yarn
https://create-react-app.dev/docs/adding-typescript/#installation