2021-09-27 12:49:36 +00:00
|
|
|
import { join, resolve } from 'pathe'
|
2022-02-28 16:11:46 +00:00
|
|
|
import { isDevelopment } from 'std-env'
|
2021-03-28 20:14:04 +00:00
|
|
|
import createRequire from 'create-require'
|
|
|
|
import { pascalCase } from 'scule'
|
|
|
|
import jiti from 'jiti'
|
2021-10-18 09:07:09 +00:00
|
|
|
import defu from 'defu'
|
2022-08-26 15:47:29 +00:00
|
|
|
|
2022-04-11 14:34:23 +00:00
|
|
|
import { RuntimeConfig } from '../types/config'
|
2021-03-28 20:14:04 +00:00
|
|
|
|
2022-08-26 15:47:29 +00:00
|
|
|
import { defineUntypedSchema } from 'untyped'
|
|
|
|
|
|
|
|
export default defineUntypedSchema({
|
2022-01-31 21:13:58 +00:00
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Extend nested configurations from multiple local or remote sources.
|
2022-01-31 21:13:58 +00:00
|
|
|
*
|
|
|
|
* Value should be either a string or array of strings pointing to source directories or config path relative to current config.
|
|
|
|
*
|
|
|
|
* You can use `github:`, `gitlab:`, `bitbucket:` or `https://` to extend from a remote git repository.
|
|
|
|
*
|
2022-04-07 12:57:57 +00:00
|
|
|
* @type {string|string[]}
|
2022-01-31 21:13:58 +00:00
|
|
|
*
|
|
|
|
* @version 3
|
|
|
|
*/
|
|
|
|
extends: null,
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Define the workspace directory of your application.
|
|
|
|
*
|
|
|
|
* This property can be overwritten (for example, running `nuxt ./my-app/`
|
|
|
|
* will set the `rootDir` to the absolute path of `./my-app/` from the
|
|
|
|
* current/working directory.
|
|
|
|
*
|
|
|
|
* It is normally not needed to configure this option.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
rootDir: {
|
|
|
|
$resolve: val => typeof val === 'string' ? resolve(val) : process.cwd()
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Define the source directory of your Nuxt application.
|
|
|
|
*
|
2022-08-11 21:25:35 +00:00
|
|
|
* If a relative path is specified, it will be relative to the `rootDir`.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* export default {
|
|
|
|
* srcDir: 'client/'
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
* This would work with the following folder structure:
|
|
|
|
* ```bash
|
|
|
|
* -| app/
|
|
|
|
* ---| node_modules/
|
|
|
|
* ---| nuxt.config.js
|
|
|
|
* ---| package.json
|
|
|
|
* ---| client/
|
|
|
|
* ------| assets/
|
|
|
|
* ------| components/
|
|
|
|
* ------| layouts/
|
|
|
|
* ------| middleware/
|
|
|
|
* ------| pages/
|
|
|
|
* ------| plugins/
|
|
|
|
* ------| static/
|
|
|
|
* ------| store/
|
|
|
|
* ```
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
srcDir: {
|
|
|
|
$resolve: (val, get) => resolve(get('rootDir'), val || '.')
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Define the directory where your built Nuxt files will be placed.
|
|
|
|
*
|
|
|
|
* Many tools assume that `.nuxt` is a hidden directory (because it starts
|
|
|
|
* with a `.`). If that is a problem, you can use this option to prevent that.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* export default {
|
|
|
|
* buildDir: 'nuxt-build'
|
|
|
|
* }
|
|
|
|
* ```
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
buildDir: {
|
|
|
|
$resolve: (val, get) => resolve(get('rootDir'), val || '.nuxt')
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Whether Nuxt is running in development mode.
|
|
|
|
*
|
2022-08-11 21:25:35 +00:00
|
|
|
* Normally, you should not need to set this.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-11-03 14:39:38 +00:00
|
|
|
dev: Boolean(isDevelopment),
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Whether your app is being unit tested.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-11-03 14:39:38 +00:00
|
|
|
test: Boolean(isDevelopment),
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Set to `true` to enable debug mode.
|
2021-08-11 21:48:33 +00:00
|
|
|
*
|
2022-08-11 21:25:35 +00:00
|
|
|
* By default, it's only enabled in development mode.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
|
|
|
debug: {
|
|
|
|
$resolve: (val, get) => val ?? get('dev')
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* The `env` property defines environment variables that should be available
|
2021-04-15 18:49:29 +00:00
|
|
|
* throughout your app (server- and client-side). They can be assigned using
|
2022-08-11 21:25:35 +00:00
|
|
|
* server-side environment variables.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note Nuxt uses webpack's `definePlugin` to define these environment variables.
|
2021-04-15 18:49:29 +00:00
|
|
|
* This means that the actual `process` or `process.env` from Node.js is neither
|
|
|
|
* available nor defined. Each of the `env` properties defined here is individually
|
|
|
|
* mapped to `process.env.xxxx` and converted during compilation.
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note Environment variables starting with `NUXT_ENV_` are automatically injected
|
2021-04-15 18:49:29 +00:00
|
|
|
* into the process environment.
|
2021-08-11 21:48:33 +00:00
|
|
|
*
|
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
env: {
|
2021-08-11 21:48:33 +00:00
|
|
|
$default: {},
|
2021-03-28 20:14:04 +00:00
|
|
|
$resolve: (val) => {
|
|
|
|
val = { ...val }
|
|
|
|
for (const key in process.env) {
|
|
|
|
if (key.startsWith('NUXT_ENV_')) {
|
|
|
|
val[key] = process.env[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Set the method Nuxt uses to require modules, such as loading `nuxt.config`, server
|
|
|
|
* middleware, and so on - defaulting to `jiti` (which has support for TypeScript and ESM syntax).
|
|
|
|
*
|
|
|
|
* @see [jiti](https://github.com/unjs/jiti)
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {'jiti' | 'native' | ((p: string | { filename: string }) => NodeRequire)}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
createRequire: {
|
|
|
|
$resolve: (val: any) => {
|
|
|
|
val = process.env.NUXT_CREATE_REQUIRE || val ||
|
2022-08-26 15:47:29 +00:00
|
|
|
// @ts-expect-error global type
|
2022-02-15 09:50:11 +00:00
|
|
|
(typeof globalThis.jest !== 'undefined' ? 'native' : 'jiti')
|
2021-03-28 20:14:04 +00:00
|
|
|
if (val === 'jiti') {
|
2022-08-26 15:47:29 +00:00
|
|
|
return (p: string | { filename: string }) => jiti(typeof p === 'string' ? p : p.filename, { esmResolve: true })
|
2021-03-28 20:14:04 +00:00
|
|
|
}
|
|
|
|
if (val === 'native') {
|
2022-08-26 15:47:29 +00:00
|
|
|
return (p: string | { filename: string }) => createRequire(typeof p === 'string' ? p : p.filename)
|
2021-03-28 20:14:04 +00:00
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Whether your Nuxt app should be built to be served by the Nuxt server (`server`)
|
|
|
|
* or as static HTML files suitable for a CDN or other static file server (`static`).
|
|
|
|
*
|
|
|
|
* This is unrelated to `ssr`.
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {'server' | 'static'}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
target: {
|
|
|
|
$resolve: val => ['server', 'static'].includes(val) ? val : 'server'
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Whether to enable rendering of HTML - either dynamically (in server mode) or at generate time.
|
|
|
|
* If set to `false` and combined with `static` target, generated pages will simply display
|
|
|
|
* a loading screen with no content.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
ssr: true,
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* @deprecated use `ssr` option
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
mode: {
|
|
|
|
$resolve: (val, get) => val || (get('ssr') ? 'spa' : 'universal'),
|
|
|
|
$schema: { deprecated: '`mode` option is deprecated' }
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Whether to produce a separate modern build targeting browsers that support ES modules.
|
|
|
|
*
|
|
|
|
* Set to `'server'` to enable server mode, where the Nuxt server checks
|
|
|
|
* browser version based on the user agent and serves the correct bundle.
|
|
|
|
*
|
|
|
|
* Set to `'client'` to serve both the modern bundle with `<script type="module">`
|
|
|
|
* and the legacy bundle with `<script nomodule>`. It will also provide a
|
|
|
|
* `<link rel="modulepreload">` for the modern bundle. Every browser that understands
|
|
|
|
* the module type will load the modern bundle while older browsers fall back to the
|
|
|
|
* legacy (transpiled) bundle.
|
|
|
|
*
|
|
|
|
* If you have set `modern: true` and are generating your app or have `ssr: false`,
|
|
|
|
* modern will be set to `'client'`.
|
|
|
|
*
|
|
|
|
* If you have set `modern: true` and are serving your app, modern will be set to `'server'`.
|
|
|
|
*
|
|
|
|
* @see [concept of modern mode](https://philipwalton.com/articles/deploying-es2015-code-in-production-today/)
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {'server' | 'client' | boolean}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
modern: undefined,
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Modules are Nuxt extensions which can extend its core functionality and add endless integrations.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* Each module is either a string (which can refer to a package, or be a path to a file), a
|
|
|
|
* tuple with the module as first string and the options as a second object, or an inline module function.
|
|
|
|
*
|
|
|
|
* Nuxt tries to resolve each item in the modules array using node require path
|
|
|
|
* (in `node_modules`) and then will be resolved from project `srcDir` if `~` alias is used.
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note Modules are executed sequentially so the order is important.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* modules: [
|
|
|
|
* // Using package name
|
|
|
|
* '@nuxtjs/axios',
|
|
|
|
* // Relative to your project srcDir
|
|
|
|
* '~/modules/awesome.js',
|
|
|
|
* // Providing options
|
|
|
|
* ['@nuxtjs/google-analytics', { ua: 'X1234567' }],
|
|
|
|
* // Inline definition
|
|
|
|
* function () {}
|
|
|
|
* ]
|
|
|
|
* ```
|
2022-01-21 11:47:13 +00:00
|
|
|
* @type {(typeof import('../src/types/module').NuxtModule | string | [typeof import('../src/types/module').NuxtModule | string, Record<string, any>])[]}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
modules: [],
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Modules that are only required during development and build time.
|
|
|
|
*
|
2022-08-11 21:25:35 +00:00
|
|
|
* Modules are Nuxt extensions which can extend its core functionality and add endless integrations.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* Each module is either a string (which can refer to a package, or be a path to a file), a
|
|
|
|
* tuple with the module as first string and the options as a second object, or an inline module function.
|
|
|
|
*
|
|
|
|
* Nuxt tries to resolve each item in the modules array using node require path
|
|
|
|
* (in `node_modules`) and then will be resolved from project `srcDir` if `~` alias is used.
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note Modules are executed sequentially so the order is important.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* modules: [
|
|
|
|
* // Using package name
|
|
|
|
* '@nuxtjs/axios',
|
|
|
|
* // Relative to your project srcDir
|
|
|
|
* '~/modules/awesome.js',
|
|
|
|
* // Providing options
|
|
|
|
* ['@nuxtjs/google-analytics', { ua: 'X1234567' }],
|
|
|
|
* // Inline definition
|
|
|
|
* function () {}
|
|
|
|
* ]
|
|
|
|
* ```
|
|
|
|
*
|
2022-03-22 11:33:30 +00:00
|
|
|
* @note In Nuxt 2, using `buildModules` helps to make production startup faster and also significantly
|
2021-04-15 18:49:29 +00:00
|
|
|
* decreases the size of `node_modules` in production deployments. Please refer to each
|
|
|
|
* module's documentation to see if it is recommended to use `modules` or `buildModules`.
|
2021-08-11 21:48:33 +00:00
|
|
|
*
|
2022-01-21 11:47:13 +00:00
|
|
|
* @type {(typeof import('../src/types/module').NuxtModule | string | [typeof import('../src/types/module').NuxtModule | string, Record<string, any>])[]}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2022-03-22 11:33:30 +00:00
|
|
|
* @deprecated This is no longer needed in Nuxt 3 and Nuxt Bridge; all modules should be added to `modules` instead.
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
buildModules: [],
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Built-in ad-hoc modules.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
_modules: [],
|
|
|
|
|
2022-02-08 19:09:44 +00:00
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Installed module metadata.
|
2022-02-08 19:09:44 +00:00
|
|
|
*
|
|
|
|
* @version 3
|
|
|
|
* @private
|
2022-08-11 21:25:35 +00:00
|
|
|
*/
|
2022-02-08 19:09:44 +00:00
|
|
|
_installedModules: [],
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Allows customizing the global ID used in the main HTML template as well as the main
|
|
|
|
* Vue instance name and other options.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
globalName: {
|
|
|
|
$resolve: val => (typeof val === 'string' && /^[a-zA-Z]+$/.test(val)) ? val.toLocaleLowerCase() : 'nuxt'
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Customizes specific global names (they are based on `globalName` by default).
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
globals: {
|
2021-11-19 12:22:27 +00:00
|
|
|
/** @type {(globalName: string) => string} */
|
2022-08-26 15:47:29 +00:00
|
|
|
id: (globalName: string) => `__${globalName}`,
|
2021-11-19 12:22:27 +00:00
|
|
|
/** @type {(globalName: string) => string} */
|
2022-08-26 15:47:29 +00:00
|
|
|
nuxt: (globalName: string) => `$${globalName}`,
|
2021-11-19 12:22:27 +00:00
|
|
|
/** @type {(globalName: string) => string} */
|
2022-08-26 15:47:29 +00:00
|
|
|
context: (globalName: string) => `__${globalName.toUpperCase()}__`,
|
2021-11-19 12:22:27 +00:00
|
|
|
/** @type {(globalName: string) => string} */
|
2022-08-26 15:47:29 +00:00
|
|
|
pluginPrefix: (globalName: string) => globalName,
|
2021-11-19 12:22:27 +00:00
|
|
|
/** @type {(globalName: string) => string} */
|
2022-08-26 15:47:29 +00:00
|
|
|
readyCallback: (globalName: string) => `on${pascalCase(globalName)}Ready`,
|
2021-11-19 12:22:27 +00:00
|
|
|
/** @type {(globalName: string) => string} */
|
2022-08-26 15:47:29 +00:00
|
|
|
loadedCallback: (globalName: string) => `_on${pascalCase(globalName)}Loaded`
|
2021-03-28 20:14:04 +00:00
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Server middleware are connect/express/h3-shaped functions that handle server-side requests. They
|
|
|
|
* run on the server and before the Vue renderer.
|
|
|
|
*
|
2022-03-25 11:40:15 +00:00
|
|
|
* By adding entries to `serverMiddleware` you can register additional routes without the need
|
|
|
|
* for an external server.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* You can pass a string, which can be the name of a node dependency or a path to a file. You
|
2022-08-11 21:25:35 +00:00
|
|
|
* can also pass an object with `path` and `handler` keys (`handler` can be a path or a
|
|
|
|
* function).
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
2022-03-25 11:40:15 +00:00
|
|
|
* @note If you pass a function directly, it will only run in development mode.
|
|
|
|
*
|
2021-04-15 18:49:29 +00:00
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* serverMiddleware: [
|
|
|
|
* // Will register redirect-ssl npm package
|
|
|
|
* 'redirect-ssl',
|
|
|
|
* // Will register file from project server-middleware directory to handle /server-middleware/* requires
|
|
|
|
* { path: '/server-middleware', handler: '~/server-middleware/index.js' },
|
2022-03-25 11:40:15 +00:00
|
|
|
* // We can create custom instances too, but only in development mode, they are ignored for the production bundle.
|
2022-04-19 14:46:14 +00:00
|
|
|
* { path: '/static2', handler: serveStatic(fileURLToPath(new URL('./static2', import.meta.url))) }
|
2021-04-15 18:49:29 +00:00
|
|
|
* ]
|
|
|
|
* ```
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note If you don't want middleware to run on all routes you should use the object
|
2021-04-15 18:49:29 +00:00
|
|
|
* form with a specific path.
|
|
|
|
*
|
|
|
|
* If you pass a string handler, Nuxt will expect that file to export a default function
|
|
|
|
* that handles `(req, res, next) => void`.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* export default function (req, res, next) {
|
|
|
|
* // req is the Node.js http request object
|
|
|
|
* console.log(req.url)
|
|
|
|
* // res is the Node.js http response object
|
|
|
|
* // next is a function to call to invoke the next middleware
|
|
|
|
* // Don't forget to call next at the end if your middleware is not an endpoint!
|
|
|
|
* next()
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Alternatively, it can export a connect/express/h3-type app instance.
|
|
|
|
* @example
|
|
|
|
* ```js
|
2022-03-25 11:40:15 +00:00
|
|
|
* import bodyParser from 'body-parser'
|
|
|
|
* import createApp from 'express'
|
|
|
|
* const app = createApp()
|
2021-04-15 18:49:29 +00:00
|
|
|
* app.use(bodyParser.json())
|
|
|
|
* app.all('/getJSON', (req, res) => {
|
|
|
|
* res.json({ data: 'data' })
|
|
|
|
* })
|
2022-03-25 11:40:15 +00:00
|
|
|
* export default app
|
2021-04-15 18:49:29 +00:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Alternatively, instead of passing an array of `serverMiddleware`, you can pass an object
|
|
|
|
* whose keys are the paths and whose values are the handlers (string or function).
|
|
|
|
* @example
|
|
|
|
* ```js
|
2021-08-11 21:48:33 +00:00
|
|
|
* export default {
|
|
|
|
* serverMiddleware: {
|
|
|
|
* '/a': '~/server-middleware/a.js',
|
|
|
|
* '/b': '~/server-middleware/b.js',
|
|
|
|
* '/c': '~/server-middleware/c.js'
|
|
|
|
* }
|
2021-04-15 18:49:29 +00:00
|
|
|
* }
|
|
|
|
* ```
|
2022-05-06 13:31:52 +00:00
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2022-05-06 13:31:52 +00:00
|
|
|
* @deprecated Use `serverHandlers` instead
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
serverMiddleware: {
|
|
|
|
$resolve: (val: any) => {
|
|
|
|
if (!val) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
if (!Array.isArray(val)) {
|
|
|
|
return Object.entries(val).map(([path, handler]) => ({ path, handler }))
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Used to set the modules directories for path resolving (for example, webpack's
|
|
|
|
* `resolveLoading`, `nodeExternals` and `postcss`).
|
|
|
|
*
|
|
|
|
* The configuration path is relative to `options.rootDir` (default is current working directory).
|
|
|
|
*
|
|
|
|
* Setting this field may be necessary if your project is organized as a yarn workspace-styled mono-repository.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* export default {
|
|
|
|
* modulesDir: ['../../node_modules']
|
|
|
|
* }
|
|
|
|
* ```
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
modulesDir: {
|
|
|
|
$default: ['node_modules'],
|
2022-08-26 15:47:29 +00:00
|
|
|
$resolve: (val, get) => [
|
|
|
|
...val.map((dir: string) => resolve(get('rootDir'), dir)),
|
2021-04-03 12:42:02 +00:00
|
|
|
resolve(process.cwd(), 'node_modules')
|
2022-08-26 15:47:29 +00:00
|
|
|
]
|
2021-03-28 20:14:04 +00:00
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* Customize default directory structure used by Nuxt.
|
2021-08-11 21:48:33 +00:00
|
|
|
*
|
2021-04-15 18:49:29 +00:00
|
|
|
* It is better to stick with defaults unless needed.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
dir: {
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
2022-08-11 21:25:35 +00:00
|
|
|
* The assets directory (aliased as `~assets` in your build).
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
assets: 'assets',
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
|
|
|
* The directory containing app template files like `app.html` and `router.scrollBehavior.js`
|
|
|
|
* @version 2
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
app: 'app',
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
|
|
|
* The layouts directory, each file of which will be auto-registered as a Nuxt layout.
|
|
|
|
* @version 2
|
|
|
|
* @version 3
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
layouts: 'layouts',
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
|
|
|
* The middleware directory, each file of which will be auto-registered as a Nuxt middleware.
|
2022-01-27 11:13:32 +00:00
|
|
|
* @version 3
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
middleware: 'middleware',
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
|
|
|
* The directory which will be processed to auto-generate your application page routes.
|
|
|
|
* @version 2
|
|
|
|
* @version 3
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
pages: 'pages',
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
2021-06-30 10:29:48 +00:00
|
|
|
* The directory containing your static files, which will be directly accessible via the Nuxt server
|
|
|
|
* and copied across into your `dist` folder when your app is generated.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-06-30 10:29:48 +00:00
|
|
|
public: {
|
|
|
|
$resolve: (val, get) => val || get('dir.static') || 'public',
|
|
|
|
},
|
2021-08-11 21:48:33 +00:00
|
|
|
/** @version 2 */
|
2021-06-30 10:29:48 +00:00
|
|
|
static: {
|
|
|
|
$schema: { deprecated: 'use `dir.public` option instead' },
|
|
|
|
$resolve: (val, get) => val || get('dir.public') || 'public',
|
|
|
|
},
|
2021-08-11 21:48:33 +00:00
|
|
|
/**
|
|
|
|
* The folder which will be used to auto-generate your Vuex store structure.
|
|
|
|
* @version 2
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
store: 'store'
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* The extensions that should be resolved by the Nuxt resolver.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
extensions: {
|
2021-11-02 15:27:42 +00:00
|
|
|
$resolve: val => ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.vue'].concat(val).filter(Boolean)
|
2021-03-28 20:14:04 +00:00
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* The style extensions that should be resolved by the Nuxt resolver (for example, in `css` property).
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-04-02 11:47:01 +00:00
|
|
|
styleExtensions: ['.css', '.pcss', '.postcss', '.styl', '.stylus', '.scss', '.sass', '.less'],
|
2021-03-28 20:14:04 +00:00
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* You can improve your DX by defining additional aliases to access custom directories
|
|
|
|
* within your JavaScript and CSS.
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* @note Within a webpack context (image sources, CSS - but not JavaScript) you _must_ access
|
2021-04-15 18:49:29 +00:00
|
|
|
* your alias by prefixing it with `~`.
|
|
|
|
*
|
2022-02-09 21:27:35 +00:00
|
|
|
* @note These aliases will be automatically added to the generated `.nuxt/tsconfig.json` so you can get full
|
|
|
|
* type support and path auto-complete. In case you need to extend options provided by `./.nuxt/tsconfig.json`
|
|
|
|
* further, make sure to add them here or within the `typescript.tsConfig` property in `nuxt.config`.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* export default {
|
|
|
|
* alias: {
|
2022-05-18 06:15:38 +00:00
|
|
|
* 'images': fileURLToPath(new URL('./assets/images', import.meta.url)),
|
|
|
|
* 'style': fileURLToPath(new URL('./assets/style', import.meta.url)),
|
|
|
|
* 'data': fileURLToPath(new URL('./assets/other/data', import.meta.url))
|
2021-04-15 18:49:29 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* ```html
|
|
|
|
* <template>
|
|
|
|
* <img src="~images/main-bg.jpg">
|
|
|
|
* </template>
|
|
|
|
*
|
|
|
|
* <script>
|
|
|
|
* import data from 'data/test.json'
|
|
|
|
* </script>
|
|
|
|
*
|
|
|
|
* <style>
|
|
|
|
* // Uncomment the below
|
|
|
|
* //@import '~style/variables.scss';
|
|
|
|
* //@import '~style/utils.scss';
|
|
|
|
* //@import '~style/base.scss';
|
|
|
|
* body {
|
|
|
|
* background-image: url('~images/main-bg.jpg');
|
|
|
|
* }
|
|
|
|
* </style>
|
|
|
|
* ```
|
2021-08-11 21:48:33 +00:00
|
|
|
*
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {Record<string, string>}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
alias: {
|
|
|
|
$resolve: (val, get) => ({
|
|
|
|
'~~': get('rootDir'),
|
|
|
|
'@@': get('rootDir'),
|
|
|
|
'~': get('srcDir'),
|
|
|
|
'@': get('srcDir'),
|
|
|
|
[get('dir.assets')]: join(get('srcDir'), get('dir.assets')),
|
2022-03-12 07:17:55 +00:00
|
|
|
[get('dir.public')]: join(get('srcDir'), get('dir.public')),
|
2021-03-28 20:14:04 +00:00
|
|
|
...val
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Pass options directly to `node-ignore` (which is used by Nuxt to ignore files).
|
|
|
|
*
|
|
|
|
* @see [node-ignore](https://github.com/kaelzhang/node-ignore)
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* ignoreOptions: {
|
|
|
|
* ignorecase: false
|
|
|
|
* }
|
|
|
|
* ```
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2022-02-28 16:11:46 +00:00
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
ignoreOptions: undefined,
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Any file in `pages/`, `layouts/`, `middleware/` or `store/` will be ignored during
|
|
|
|
* building if its filename starts with the prefix specified by `ignorePrefix`.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2022-02-28 16:11:46 +00:00
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
ignorePrefix: '-',
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* More customizable than `ignorePrefix`: all files matching glob patterns specified
|
|
|
|
* inside the `ignore` array will be ignored in building.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2022-02-28 16:11:46 +00:00
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
ignore: {
|
|
|
|
$resolve: (val, get) => [
|
2022-02-28 16:11:46 +00:00
|
|
|
'**/*.stories.{js,ts,jsx,tsx}', // ignore storybook files
|
|
|
|
'**/*.{spec,test}.{js,ts,jsx,tsx}', // ignore tests
|
|
|
|
'.output',
|
2021-03-28 20:14:04 +00:00
|
|
|
get('ignorePrefix') && `**/${get('ignorePrefix')}*.*`
|
|
|
|
].concat(val).filter(Boolean)
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* The watch property lets you watch custom files for restarting the server.
|
|
|
|
*
|
|
|
|
* `chokidar` is used to set up the watchers. To learn more about its pattern
|
|
|
|
* options, see chokidar documentation.
|
|
|
|
*
|
|
|
|
* @see [chokidar](https://github.com/paulmillr/chokidar#api)
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* watch: ['~/custom/*.js']
|
|
|
|
* ```
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {string[]}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
watch: {
|
2021-04-15 19:17:44 +00:00
|
|
|
$resolve: (val, get) => {
|
|
|
|
const rootDir = get('rootDir')
|
|
|
|
return Array.from(new Set([].concat(val, get('_nuxtConfigFiles'))
|
|
|
|
.filter(Boolean).map(p => resolve(rootDir, p))
|
|
|
|
))
|
|
|
|
}
|
2021-03-28 20:14:04 +00:00
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* The watchers property lets you overwrite watchers configuration in your `nuxt.config`.
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
watchers: {
|
2021-04-15 18:49:29 +00:00
|
|
|
/** An array of event types, which, when received, will cause the watcher to restart. */
|
2021-03-28 20:14:04 +00:00
|
|
|
rewatchOnRawEvents: undefined,
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* `watchOptions` to pass directly to webpack.
|
|
|
|
*
|
|
|
|
* @see [webpack@4 watch options](https://v4.webpack.js.org/configuration/watch/#watchoptions).
|
|
|
|
* */
|
2021-03-28 20:14:04 +00:00
|
|
|
webpack: {
|
|
|
|
aggregateTimeout: 1000
|
|
|
|
},
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Options to pass directly to `chokidar`.
|
|
|
|
*
|
|
|
|
* @see [chokidar](https://github.com/paulmillr/chokidar#api)
|
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
chokidar: {
|
|
|
|
ignoreInitial: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Your preferred code editor to launch when debugging.
|
|
|
|
*
|
|
|
|
* @see [documentation](https://github.com/yyx990803/launch-editor#supported-editors)
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {string}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
editor: undefined,
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
2021-08-11 21:48:33 +00:00
|
|
|
* Hooks are listeners to Nuxt events that are typically used in modules,
|
|
|
|
* but are also available in `nuxt.config`.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* Internally, hooks follow a naming pattern using colons (e.g., build:done).
|
|
|
|
*
|
2021-08-11 21:48:33 +00:00
|
|
|
* For ease of configuration, you can also structure them as an hierarchical
|
|
|
|
* object in `nuxt.config` (as below).
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @example
|
2022-04-15 15:19:05 +00:00
|
|
|
* ```js'node:fs'
|
|
|
|
* import fs from 'node:fs'
|
|
|
|
* import path from 'node:path'
|
2021-04-15 18:49:29 +00:00
|
|
|
* export default {
|
|
|
|
* hooks: {
|
|
|
|
* build: {
|
|
|
|
* done(builder) {
|
|
|
|
* const extraFilePath = path.join(
|
|
|
|
* builder.nuxt.options.buildDir,
|
|
|
|
* 'extra-file'
|
|
|
|
* )
|
|
|
|
* fs.writeFileSync(extraFilePath, 'Something extra')
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2021-11-19 12:22:27 +00:00
|
|
|
* @type {typeof import('../src/types/hooks').NuxtHooks}
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
hooks: null,
|
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/**
|
|
|
|
* Runtime config allows passing dynamic config and environment variables to the Nuxt app context.
|
2022-02-08 19:09:44 +00:00
|
|
|
*
|
2022-04-11 14:34:23 +00:00
|
|
|
* The value of this object is accessible from server only using `useRuntimeConfig`.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
2022-04-11 14:34:23 +00:00
|
|
|
* It mainly should hold _private_ configuration which is not exposed on the frontend.
|
2021-04-15 18:49:29 +00:00
|
|
|
* This could include a reference to your API secret tokens.
|
2022-02-08 19:09:44 +00:00
|
|
|
*
|
2022-04-11 14:34:23 +00:00
|
|
|
* Anything under `public` and `app` will be exposed to the frontend as well.
|
|
|
|
*
|
2022-02-07 10:20:53 +00:00
|
|
|
* Values are automatically replaced by matching env variables at runtime, e.g. setting an environment
|
2022-08-29 09:47:02 +00:00
|
|
|
* variable `NUXT_API_KEY=my-api-key NUXT_PUBLIC_BASE_URL=/foo/` would overwrite the two values in the example below.
|
2021-04-15 18:49:29 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* export default {
|
2022-04-11 14:34:23 +00:00
|
|
|
* runtimeConfig: {
|
2022-05-18 06:16:24 +00:00
|
|
|
* apiKey: '' // Default to an empty string, automatically set at runtime using process.env.NUXT_API_KEY
|
2022-04-11 14:34:23 +00:00
|
|
|
* public: {
|
|
|
|
* baseURL: '' // Exposed to the frontend as well.
|
|
|
|
* }
|
2021-04-15 18:49:29 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2022-04-11 14:34:23 +00:00
|
|
|
* @type {typeof import('../src/types/config').RuntimeConfig}
|
|
|
|
* @version 3
|
|
|
|
*/
|
|
|
|
runtimeConfig: {
|
|
|
|
$resolve: (val: RuntimeConfig, get) => defu(val, {
|
|
|
|
...get('publicRuntimeConfig'),
|
|
|
|
...get('privateRuntimeConfig'),
|
|
|
|
public: get('publicRuntimeConfig'),
|
|
|
|
app: {
|
2022-04-19 19:12:28 +00:00
|
|
|
baseURL: get('app').baseURL,
|
|
|
|
buildAssetsDir: get('app').buildAssetsDir,
|
|
|
|
cdnURL: get('app').cdnURL,
|
2022-04-11 14:34:23 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2021-11-21 16:14:46 +00:00
|
|
|
* @type {typeof import('../src/types/config').PrivateRuntimeConfig}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2022-08-11 21:25:35 +00:00
|
|
|
* @deprecated Use `runtimeConfig` option.
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2021-03-28 20:14:04 +00:00
|
|
|
privateRuntimeConfig: {},
|
2021-04-15 18:49:29 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-21 16:14:46 +00:00
|
|
|
* @type {typeof import('../src/types/config').PublicRuntimeConfig}
|
2021-08-11 21:48:33 +00:00
|
|
|
* @version 2
|
|
|
|
* @version 3
|
2022-08-11 21:25:35 +00:00
|
|
|
* @deprecated Use `runtimeConfig` option with `public` key (`runtimeConfig.public.*`).
|
2021-04-15 18:49:29 +00:00
|
|
|
*/
|
2022-08-17 15:23:13 +00:00
|
|
|
publicRuntimeConfig: {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additional app configuration
|
|
|
|
*
|
|
|
|
* For programmatic usage and type support, you can directly provide app config with this option.
|
|
|
|
* It will be merged with `app.config` file as default value.
|
|
|
|
*
|
|
|
|
* @type {typeof import('../src/types/config').AppConfig}
|
|
|
|
* @version 3
|
|
|
|
*/
|
2022-08-29 10:42:05 +00:00
|
|
|
appConfig: {},
|
2022-08-26 15:47:29 +00:00
|
|
|
})
|