2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2021-03-28 20:14:04 +00:00
|
|
|
import { joinURL } from 'ufo'
|
|
|
|
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
|
|
|
* @version 2
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
export default {
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Directory name that holds all the assets and generated pages for a `static` build.
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
dir: {
|
|
|
|
$resolve: (val = 'dist', get) => resolve(get('rootDir'), val)
|
|
|
|
},
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The routes to generate.
|
|
|
|
*
|
|
|
|
* If you are using the crawler, this will be only the starting point for route generation.
|
|
|
|
* This is often necessary when using dynamic routes.
|
|
|
|
*
|
|
|
|
* It can be an array or a function.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* routes: ['/users/1', '/users/2', '/users/3']
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* You can pass a function that returns a promise or a function that takes a callback. It should
|
|
|
|
* return an array of strings or objects with `route` and (optional) `payload` keys.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
2021-08-11 21:48:33 +00:00
|
|
|
* export default {
|
|
|
|
* generate: {
|
|
|
|
* async routes() {
|
|
|
|
* const res = await axios.get('https://my-api/users')
|
|
|
|
* return res.data.map(user => ({ route: '/users/' + user.id, payload: user }))
|
|
|
|
* }
|
|
|
|
* }
|
2021-04-15 18:49:29 +00:00
|
|
|
* }
|
2021-08-11 21:48:33 +00:00
|
|
|
* ```
|
|
|
|
* Or instead:
|
|
|
|
* ```js
|
|
|
|
* export default {
|
|
|
|
* generate: {
|
|
|
|
* routes(callback) {
|
|
|
|
* axios
|
|
|
|
* .get('https://my-api/users')
|
|
|
|
* .then(res => {
|
|
|
|
* const routes = res.data.map(user => '/users/' + user.id)
|
|
|
|
* callback(null, routes)
|
|
|
|
* })
|
|
|
|
* .catch(callback)
|
|
|
|
* }
|
|
|
|
* }
|
2021-04-15 18:49:29 +00:00
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* If `routes()` returns a payload, it can be accessed from the Nuxt context.
|
|
|
|
* @example
|
|
|
|
* ```js
|
2021-08-11 21:48:33 +00:00
|
|
|
* export default {
|
2021-10-08 14:21:55 +00:00
|
|
|
* async useAsyncData ({ params, error, payload }) {
|
2021-08-11 21:48:33 +00:00
|
|
|
* if (payload) return { user: payload }
|
|
|
|
* else return { user: await backend.fetchUser(params.id) }
|
|
|
|
* }
|
2021-04-15 18:49:29 +00:00
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
routes: [],
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of string or regular expressions that will prevent generation
|
|
|
|
* of routes matching them. The routes will still be accessible when `fallback` is set.
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
exclude: [],
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/** The number of routes that are generated concurrently in the same thread. */
|
2021-03-28 20:14:04 +00:00
|
|
|
concurrency: 500,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Interval in milliseconds between two render cycles to avoid flooding a potential
|
|
|
|
* API with calls.
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
interval: 0,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to `false` to disable creating a directory + `index.html` for each route.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```bash
|
|
|
|
* # subFolders: true
|
|
|
|
* -| dist/
|
|
|
|
* ---| index.html
|
|
|
|
* ---| about/
|
|
|
|
* -----| index.html
|
|
|
|
* ---| products/
|
|
|
|
* -----| item/
|
|
|
|
* -------| index.html
|
|
|
|
*
|
|
|
|
* # subFolders: false
|
|
|
|
* -| dist/
|
|
|
|
* ---| index.html
|
|
|
|
* ---| about.html
|
|
|
|
* ---| products/
|
|
|
|
* -----| item.html
|
|
|
|
* ```
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
subFolders: true,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The path to the fallback HTML file.
|
|
|
|
*
|
|
|
|
* Set this as the error page in your static server configuration, so that unknown
|
|
|
|
* routes can be rendered (on the client-side) by Nuxt.
|
|
|
|
*
|
|
|
|
* * If unset or set to a falsy value, the name of the fallback HTML file will be `200.html`.
|
|
|
|
* * If set to true, the filename will be `404.html`.
|
|
|
|
* * If you provide a string as a value, it will be used instead.
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note Multiple services (e.g. Netlify) detect a `404.html` automatically. If
|
2021-04-15 18:49:29 +00:00
|
|
|
* you configure your web server on your own, please consult its documentation
|
|
|
|
* to find out how to set up an error page (and set it to the 404.html file)
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
fallback: { $resolve: val => val === true ? '400.html' : (val || '200.html') },
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to `false` to disable generating pages discovered through crawling relative
|
|
|
|
* links in generated pages.
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
crawler: true,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/** Set to `false` to disable generating a `manifest.js` with a list of all generated pages. */
|
2021-03-28 20:14:04 +00:00
|
|
|
manifest: true,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/** Set to `false` to disable generating a `.nojekyll` file (which aids compatibility with GitHub Pages). */
|
2021-03-28 20:14:04 +00:00
|
|
|
nojekyll: true,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure the cache (used with `static` target to avoid rebuilding when no files have changed).
|
|
|
|
*
|
|
|
|
* Set to `false` to disable completely.
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
cache: {
|
2021-04-15 18:49:29 +00:00
|
|
|
/** An array of files or directories to ignore. (It can also be a function that returns an array.) */
|
2021-03-28 20:14:04 +00:00
|
|
|
ignore: [],
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Options to pass to [`globby`](https://github.com/sindresorhus/globby), which
|
|
|
|
* is used to generate a 'snapshot' of the source files.
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
globbyOptions: {
|
|
|
|
gitignore: true
|
|
|
|
}
|
|
|
|
},
|
2021-04-15 18:49:29 +00:00
|
|
|
|
2021-03-28 20:14:04 +00:00
|
|
|
staticAssets: {
|
2021-04-15 18:49:29 +00:00
|
|
|
/** The directory underneath `/_nuxt/`, where static assets (payload, state and manifest files) will live. */
|
2021-03-28 20:14:04 +00:00
|
|
|
dir: 'static',
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* The full path to the directory underneath `/_nuxt/` where static assets
|
|
|
|
* (payload, state and manifest files) will live.
|
|
|
|
*/
|
2022-04-19 19:12:28 +00:00
|
|
|
base: { $resolve: (val, get) => val || joinURL(get('app').buildAssetsDir, get('generate.dir')) },
|
2021-04-15 18:49:29 +00:00
|
|
|
/** The full path to the versioned directory where static assets for the current buidl are located. */
|
2021-03-28 20:14:04 +00:00
|
|
|
versionBase: { $resolve: (val, get) => val || joinURL(get('generate.base'), get('generate.version')) },
|
2021-04-15 18:49:29 +00:00
|
|
|
/** A unique string to uniquely identify payload versions (defaults to the current timestamp). */
|
2021-03-28 20:14:04 +00:00
|
|
|
version: { $resolve: val => val || (String(Math.round(Date.now() / 1000))) }
|
|
|
|
}
|
|
|
|
}
|