-
Notifications
You must be signed in to change notification settings - Fork 0
Internal Tutorials
Nx is a build system with tooling to help manage monorepos. We will mainly be using it to generate files for us.
Caution
Ensure all nx commands are executed within the root of the project.
Heres how we can generate a new component with the name navbar in the shared/budgie-components folder
nx g @nx/next:component navbar --project=shared-budgie-components
# Nx uses "-" instead of forward slashes when specifying project locations
#we can also generate pages for our next app with:
nx g @nx/next:page my-new-page --directory=dir-where-to-place-the-page
Choosing CSS as our styling option and derived path will generate the following files:
![Screenshot 2024-05-29 at 18 52 13](https://private-user-images.githubusercontent.com/148685970/334893289-e773b7fd-425d-43b2-b690-668bf30fb0be.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MTA2NjAsIm5iZiI6MTczOTgxMDM2MCwicGF0aCI6Ii8xNDg2ODU5NzAvMzM0ODkzMjg5LWU3NzNiN2ZkLTQyNWQtNDNiMi1iNjkwLTY2OGJmMzBmYjBiZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxN1QxNjM5MjBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01NTcwODM1NzY0ZjYwMmE5MTcwYTZhNGY0NWYyMDI0ZWI1MzNlY2M2NmM1YWYwOGVjNjcxYzdkYzk5ZWI1OTJkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.YKiNDl1mXx5pWBaHxlAYZY1t-ImGIU31ExkZM43_OVc)
Nx also generates a suite of commands we can use to start our app in development mode, run tests, build our code and much more. The commands can be accessed within the Nx Extension in VisualStudio Code. For more on Nx and specific commands see the docs here.
Eg. Starting development server
nx run budgie-app:dev
# general format is nx run <Project>:task
Storybook is a frontend toll that will help us build UI elements in isolation.
For each component you must create a file named
<component_name>.stories.js
import { NavBar } from './NavBar';
export default {
component: navbar,
parameters: {
layout: 'fullscreen'
}
};
export const DefaultNavBar = {
render: () => <NavBar />, // this function specifies how to render a variant
};
This file makes storybook aware of our component and how we want to render it. We can then start the storybook server through the Nx extension or run:
nx run shared-budgie-components:storybook
For more on Storybook see the docs here