LoginSignup
11
6

yarnでcreate-react-appをするには?

Last updated at Posted at 2022-04-12

Reactのアプリの雛形を作成するコマンドといえば

npx create-react-app my-app

に馴染みがあるのではないでしょうか。
私も特に疑問も持たずに、これまでこのコマンドでアプリを生成してきました。

しかし、これだと開発を進めていく際にyarnコマンドでパッケージの追加を使うとpackage-lock.jsonyarn.lockがどちらもある状態になってしまい気持ち悪いことになります。

一旦、package-lock.jsonnode_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

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6