Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/revskill10/now-dev-cli
A replacement for next-cli with compatible Now V2 config
https://github.com/revskill10/now-dev-cli
nextjs
Last synced: 3 months ago
JSON representation
A replacement for next-cli with compatible Now V2 config
- Host: GitHub
- URL: https://github.com/revskill10/now-dev-cli
- Owner: revskill10
- Created: 2018-12-03T09:18:43.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-05T08:17:58.000Z (4 months ago)
- Last Synced: 2024-10-06T20:43:16.237Z (4 months ago)
- Topics: nextjs
- Language: JavaScript
- Size: 11.7 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Now Dev CLI
[![npm version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=js&type=6&v=1.2.4&x2=0)](https://www.npmjs.com/package/now-dev-cli)
A development server for Now V2 (for NextJS applications)
## Installation
```
npm i -g now-dev-cli
```## Usage
Step 1: Create your own `now.config.js`:
```js
const buildTypes = [
"@now/next",
"@now/static"
]
const builds = [
{
src: "next.config.js", use: buildTypes[0]
},
{
src: "static", use: buildTypes[1]
}
]const nextRoutes = ['/about'].map(function(item, index) {
return {
src: item,
dest: item,
build: buildTypes[0],
}
})const deployConfig = {
version: 2,
name: "next-routes-middleware",
public: true,
alias: "next-routes-middleware"
}const patterns = {
first: "(?.*)",
uuid: "(?[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}",
slug:"(?[^/]*)",
year:"(?[0-9]{4})",
month:"(?[0-9]{2})",
day:"(?[0-9]{2})"
}const routes = [
{
src: "/favicon.ico",
dest: "static/favicon.ico",
build: buildTypes[0],
},
...nextRoutes,
{
src: `/w/${patterns.first}`,
dest: "/work?slug=${first}",
build: buildTypes[0],
},
{
src: `/resource/${patterns.uuid}`,
dest: "/complex?id=${uuid}",
build: buildTypes[0],
},
{
src: `/t/${patterns.slug}/${patterns.year}-${patterns.month}-${patterns.day}`,
dest: "/more_complex?day=${day}&month=${month}&year=${year}&slug=${slug}" ,
build: buildTypes[0],
},
{ src: "/", dest: "/index", build: buildTypes[0], }
]module.exports = {
...deployConfig,
patterns,
builds,
routes,
}```
Step 2: Run `now-dev` to serve your NextJS applicationYou can also provide `-prefix ` to produce prefixed routes in a monorepo application
Compiled JSON file:
```json
{
"version": 2,
"name": "next-routes-middleware",
"public": true,
"alias": "next-routes-middleware",
"patterns": {
"first": "(?.*)",
"uuid": "(?[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}",
"slug": "(?[^/]*)",
"year": "(?[0-9]{4})",
"month": "(?[0-9]{2})",
"day": "(?[0-9]{2})"
},
"builds": [
{
"src": "next.config.js",
"use": "@now/next"
},
{
"src": "static",
"use": "@now/static"
}
],
"routes": [
{
"src": "/favicon.ico",
"dest": "static/favicon.ico"
},
{
"src": "/about",
"dest": "/about"
},
{
"src": "/w/(?.*)",
"dest": "/work?slug=$first"
},
{
"src": "/resource/(?[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}",
"dest": "/complex?id=$uuid"
},
{
"src": "/t/(?[^/]*)/(?[0-9]{4})-(?[0-9]{2})-(?[0-9]{2})",
"dest": "/more_complex?day=$day&month=$month&year=$year&slug=$slug"
},
{
"src": "/",
"dest": "/index"
}
]
}
```