https://github.com/Rychillie/monorepo
https://github.com/Rychillie/monorepo
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/Rychillie/monorepo
- Owner: Rychillie
- Created: 2021-05-28T00:55:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-28T01:14:02.000Z (over 4 years ago)
- Last Synced: 2024-11-27T10:36:15.875Z (11 months ago)
- Language: JavaScript
- Homepage: home-sage.vercel.app
- Size: 200 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - Rychillie/monorepo - (JavaScript)
README
# Using multiple zones
With Next.js you can use multiple apps as a single app using its [multi-zones feature](https://nextjs.org/docs/advanced-features/multi-zones). This is an example showing how to use it.
- All pages should be unique across zones. For example, the `home` app should not have a `pages/blog/index.js` page.
- The `home` app is the main app and therefore it includes the rewrites that map to the `blog` app in [next.config.js](home/next.config.js)
- The `blog` app sets [`basePath`](https://nextjs.org/docs/api-reference/next.config.js/basepath) to `/blog` so that generated pages, Next.js assets and public assets are within the `/blog` subfolder.## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
```bash
npx create-next-app --example with-zones with-zones-app
# or
yarn create next-app --example with-zones with-zones-app
```With multi zones you have multiple Next.js apps over a single app, therefore every app has its own dependencies and it runs independently.
To start the `/home` run the following commands from the root directory:
```bash
cd home
npm install && npm run dev
# or
cd home
yarn && yarn dev
```The `/home` app should be up and running in [http://localhost:3000](http://localhost:3000)!
Starting the `/blog` app follows a very similar process. In a new terminal, run the following commands from the root directory :
```bash
cd blog
npm install && npm run dev
# or
cd blog
yarn && yarn dev
```The `blog` app should be up and running in [http://localhost:4000](http://localhost:4000)!
### Deploy on Vercel
You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
#### Deploy Your Local Project
To deploy the apps to Vercel, we'll use [monorepos support](https://vercel.com/blog/monorepos) to create a new project for each app.
To get started, push the example to GitHub/GitLab/Bitbucket and [import your repo to Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example). We're not interested in the root directory, so make sure to select the `blog` directory (do not start with `home`):

Click continue and finish the import process. After that's done copy the domain URL that was assigned to your project, paste it on `home/.env`, and push the change to your repo:
```bash
# Replace this URL with the URL of your blog app
BLOG_URL="https://with-zones-blog.vercel.app"
```Now we'll go over the [import flow](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) again using the same repo but this time select the `home` directory instead:

With the `home` app deployed you should now be able to see both apps running under the same domain!
Any future commits to the repo will trigger a deployment to the connected Vercel projects. See the [blog post about monorepos](https://vercel.com/blog/monorepos) to learn more.