Yarn Commands for Next.js/React.js Projects
1. Initialize a New Project
Use the following command to initialize a new project and create a package.json
file:
yarn init
2. Install Project Dependencies
Install all project dependencies listed in the package.json
file:
yarn install
3. Add a Dependency
Add a new dependency to your project:
yarn add <package-name>
Example: Adding React as a dependency:
yarn add react
4. Remove a Dependency
Remove a dependency from your project:
yarn remove <package-name>
Example: Removing React as a dependency:
yarn remove react
5. Update Dependencies
Update project dependencies to their latest compatible versions:
yarn upgrade
To update a specific package, use:
yarn upgrade <package-name>
6. Start the Development Server
Start the development server for your Next.js or React.js application:
yarn start
7. Build for Production
Build your project for production:
yarn build
8. Run Tests
Run your project's test suite:
yarn test
9. Run Custom Scripts
Execute a custom script defined in the package.json
file:
yarn run <script-name>
Example: Running a script named lint
:
yarn run lint
10. Clean Project
Remove the node_modules
directory to start fresh:
yarn clean
These commands will help you manage dependencies, start the development server, build for production, run tests, and execute custom scripts in your Next.js or React.js project. Remember to run these commands in your project's root directory using the terminal or command prompt.
Feel free to refer to the Yarn documentation for more information about each command. Happy coding!