-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
54 lines (47 loc) · 1.73 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Configure static generation rules
*/
import { isGenerating } from '../helpers/env'
export default function() {
// Support falling back to a resolvable file on Netlify if a route didn't
// exist when build was run. We only want this to run when _not_ using
// generate so we return true 404s.
this.options.generate.fallback = isGenerating ? false : '404.html'
// Restrict the number of simulateneous requests so we don't consume too
// many server connections. 500 is nuxt default
if (this.options.generate.concurrency == 500) {
this.options.generate.concurrency = 20
}
// Don't use Nuxt 2.13 Crawler since we're explicitly creating all the
// routes we care about and don't want to generate dead links.
this.options.generate.crawler = false
// Sub folders, set to false to remove the trailing slashes
this.options.generate.subFolders = false
// Immediately exit for route level errors, like Axios errors. The errors
// array looks like:
// {
// type: 'unhandled',
// route: '/products/cam-wall-mounting-kit/19731607617609',
// error: // An actual exception object
// }
this.nuxt.hook('generate:routeFailed', ({ errors }) => {
errors.forEach(error => console.error(error))
process.exit(1)
})
// Abort SSG if any of the errors weren't 404s with an "ENOENT" error. The
// 404 errors don't fire the generate:routeFailed hook for some reason. The
// errors array contains objects that look like:
// {
// type: 'handled',
// route: '/products/play-time-fabric-sock',
// error: {
// statusCode: 404,
// message: 'Page not found'
// }
// }
this.nuxt.hook('generate:done', (generator, errors) => {
if (errors.filter((error) => {
return error?.error?.statusCode != 404
}).length) process.exit(2)
})
}