Skip to content

Commit 4cfa704

Browse files
kidonngNataliaTepluhina
authored andcommitted
docs: update Now deployment guide (#4395)
1 parent 29b9383 commit 4cfa704

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

docs/guide/deployment.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -267,71 +267,75 @@ Please refer to the [Firebase Documentation](https://firebase.google.com/docs/ho
267267

268268
This example uses the latest Now platform version 2.
269269

270-
1. Install the Now CLI globally:
270+
1. Install the Now CLI:
271271

272272
```bash
273273
npm install -g now
274+
275+
# Or, if you prefer a local one
276+
npm install now
274277
```
275278

276279
2. Add a `now.json` file to your project root:
277280

278281
```json
279-
{
280-
"name": "my-example-app",
281-
"version": 2,
282-
"builds": [
283-
{ "src": "dist/**", "use": "@now/static" }
284-
],
285-
"routes": [
286-
{ "src": "/(.*)", "dest": "dist/$1" }
287-
],
288-
"alias": "vue-example"
289-
}
290-
```
291-
292-
In case you want to deploy an application with router mode set to history, the config file should look like the following (if you have different folder names, update your config accordingly):
293-
```json
294282
{
295283
"name": "my-example-app",
296284
"version": 2,
297285
"builds": [
298286
{
299-
"src": "dist/**",
300-
"use": "@now/static"
287+
"src": "package.json",
288+
"use": "@now/static-build"
301289
}
302290
],
303291
"routes": [
304292
{
305-
"src": "/(js|css|img)/(.*)",
306-
"dest": "/dist/$1/$2"
307-
},
308-
{
309-
"src": "/favicon.ico",
310-
"dest": "/dist/favicon.ico"
293+
"src": "/(js|css|img)/.*",
294+
"headers": { "cache-control": "max-age=31536000, immutable" }
311295
},
312-
{
313-
"src": "/(.*)",
314-
"dest": "/dist"
315-
}
296+
{ "handle": "filesystem" },
297+
{ "src": ".*", "dest": "/" }
316298
],
317-
"alias": "vue-example"
299+
"alias": "example.com"
318300
}
319-
```
320-
This additional config is required in order to avoid issues when directly deep-linking to a specific page (e.g. when opening `my-example-app.now.sh/some-subpage`, you would be presented with a 404 error otherwise).
301+
```
321302

322-
3. Adding a deployment script in `package.json`:
303+
If you have different/additional folders, modify the route accordingly:
304+
305+
```diff
306+
- {
307+
- "src": "/(js|css|img)/.*",
308+
- "headers": { "cache-control": "max-age=31536000, immutable" }
309+
- }
310+
+ {
311+
+ "src": "/(js|css|img|fonts|media)/.*",
312+
+ "headers": { "cache-control": "max-age=31536000, immutable" }
313+
+ }
314+
```
323315

324-
```json
325-
"deploy": "npm run build && now --target production"
316+
If your `outputDir` is not the default `dist`, say `build`:
317+
318+
```diff
319+
- {
320+
- "src": "package.json",
321+
- "use": "@now/static-build"
322+
- }
323+
+ {
324+
+ "src": "package.json",
325+
+ "use": "@now/static-build",
326+
+ "config": { "distDir": "build" }
327+
+ }
326328
```
327329

328-
If you want to deploy publicly by default, you can change the deployment script to the following one:
330+
3. Adding a `now-build` script in `package.json`:
329331

330332
```json
331-
"deploy": "npm run build && now --target production --public"
333+
"now-build": "npm run build"
332334
```
335+
336+
To make a deployment, run `now`.
333337

334-
This will automatically point your site's alias to the latest deployment. Now, just run `npm run deploy` to deploy your app.
338+
If you want your deployment aliased, run `now --target production` instead.
335339

336340
### Stdlib
337341

0 commit comments

Comments
 (0)