import { join, resolve } from 'upath'
import env from 'std-env'
import createRequire from 'create-require'
import { pascalCase } from 'scule'
import jiti from 'jiti'
export default {
/**
* 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.
* @version 2
* @version 3
*/
rootDir: {
$resolve: val => typeof val === 'string' ? resolve(val) : process.cwd()
},
/**
* Define the source directory of your Nuxt application.
*
* If a relative path is specified it will be relative to the `rootDir`.
*
* @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/
* ```
* @version 2
* @version 3
*/
srcDir: {
$resolve: (val, get) => resolve(get('rootDir'), val || '.')
},
/**
* 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'
* }
* ```
* @version 2
* @version 3
*/
buildDir: {
$resolve: (val, get) => resolve(get('rootDir'), val || '.nuxt')
},
/**
* Whether Nuxt is running in development mode.
*
* Normally you should not need to set this.
* @version 2
* @version 3
*/
dev: Boolean(env.dev),
/**
* Whether your app is being unit tested
* @version 2
*/
test: Boolean(env.test),
/**
* Set to true to enable debug mode.
*
* By default it's only enabled in development mode.
* @version 2
*/
debug: {
$resolve: (val, get) => val ?? get('dev')
},
/**
* The env property defines environment variables that should be available
* throughout your app (server- and client-side). They can be assigned using
* server side environment variables.
*
* @note Nuxt uses webpack's `definePlugin` to define these environment variables.
* 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.
*
* @note Environment variables starting with `NUXT_ENV_` are automatically injected
* into the process environment.
*
* @version 2
*/
env: {
$default: {},
$resolve: (val) => {
val = { ...val }
for (const key in process.env) {
if (key.startsWith('NUXT_ENV_')) {
val[key] = process.env[key]
}
}
return val
}
},
/**
* 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)
* @version 2
*/
createRequire: {
$resolve: (val: any) => {
val = process.env.NUXT_CREATE_REQUIRE || val ||
(typeof jest !== 'undefined' ? 'native' : 'jiti')
if (val === 'jiti') {
return p => jiti(typeof p === 'string' ? p : p.filename)
}
if (val === 'native') {
return p => createRequire(typeof p === 'string' ? p : p.filename)
}
return val
}
},
/**
* 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`.
* @version 2
*/
target: {
$resolve: val => ['server', 'static'].includes(val) ? val : 'server'
},
/**
* 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.
* @version 2
* @version 3
*/
ssr: true,
/**
* @deprecated use ssr option
*/
mode: {
$resolve: (val, get) => val || (get('ssr') ? 'spa' : 'universal'),
$schema: { deprecated: '`mode` option is deprecated' }
},
/**
* 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 `
*
*
* ```
*
* @version 2
* @version 3
*/
alias: {
$resolve: (val, get) => ({
'~~': get('rootDir'),
'@@': get('rootDir'),
'~': get('srcDir'),
'@': get('srcDir'),
[get('dir.assets')]: join(get('srcDir'), get('dir.assets')),
[get('dir.static')]: join(get('srcDir', get('dir.static'))),
...val
})
},
/**
* 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
* }
* ```
* @version 2
*/
ignoreOptions: undefined,
/**
* Any file in `pages/`, `layouts/`, `middleware/` or `store/` will be ignored during
* building if its filename starts with the prefix specified by `ignorePrefix`.
* @version 2
*/
ignorePrefix: '-',
/**
* More customizable than `ignorePrefix`: all files matching glob patterns specified
* inside the `ignore` array will be ignored in building.
* @version 2
*/
ignore: {
$resolve: (val, get) => [
'**/*.test.*',
'**/*.spec.*',
get('ignorePrefix') && `**/${get('ignorePrefix')}*.*`
].concat(val).filter(Boolean)
},
/**
* 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']
* ```
* @version 2
*/
watch: {
$resolve: (val, get) => {
const rootDir = get('rootDir')
return Array.from(new Set([].concat(val, get('_nuxtConfigFiles'))
.filter(Boolean).map(p => resolve(rootDir, p))
))
}
},
/**
* The watchers property lets you overwrite watchers configuration in your `nuxt.config`.
* @version 2
* @version 3
*/
watchers: {
/** An array of event types, which, when received, will cause the watcher to restart. */
rewatchOnRawEvents: undefined,
/**
* `watchOptions` to pass directly to webpack.
*
* @see [webpack@4 watch options](https://v4.webpack.js.org/configuration/watch/#watchoptions).
* */
webpack: {
aggregateTimeout: 1000
},
/**
* Options to pass directly to `chokidar`.
*
* @see [chokidar](https://github.com/paulmillr/chokidar#api)
*/
chokidar: {
ignoreInitial: true
}
},
/**
* Your preferred code editor to launch when debugging.
*
* @see [documentation](https://github.com/yyx990803/launch-editor#supported-editors)
* @version 2
*/
editor: undefined,
/**
* Hooks are listeners to Nuxt events that are typically used in modules,
* but are also available in `nuxt.config`.
*
* Internally, hooks follow a naming pattern using colons (e.g., build:done).
*
* For ease of configuration, you can also structure them as an hierarchical
* object in `nuxt.config` (as below).
*
* @example
* ```js
* import fs from 'fs'
* import path from 'path'
* export default {
* hooks: {
* build: {
* done(builder) {
* const extraFilePath = path.join(
* builder.nuxt.options.buildDir,
* 'extra-file'
* )
* fs.writeFileSync(extraFilePath, 'Something extra')
* }
* }
* }
* }
* ```
* @version 2
* @version 3
*/
hooks: null,
/**
* Runtime config allows passing dynamic config and environment variables to the Nuxt app context.
*
* It is added to the Nuxt payload so there is no need to rebuild to update your configuration in
* development or if your application is served by the Nuxt server. (For static sites you will still
* need to regenerate your site to see changes.)
*
* The value of this object is accessible from server only using `$config`.
*
* It will override `publicRuntimeConfig` on the server-side.
*
* It should hold _private_ environment variables (that should not be exposed on the frontend).
* This could include a reference to your API secret tokens.
*
* @example
* ```js
* export default {
* privateRuntimeConfig: {
* apiSecret: process.env.API_SECRET
* }
* }
* ```
* @version 2
* @version 3
*/
privateRuntimeConfig: {},
/**
* Runtime config allows passing dynamic config and environment variables to the Nuxt app context.
*
* It is added to the Nuxt payload so there is no need to rebuild to update your configuration in
* development or if your application is served by the Nuxt server. (For static sites you will still
* need to regenerate your site to see changes.)
*
* The value of this object is accessible from both client and server using `$config`. It should hold env
* variables that are _public_ as they will be accessible on the frontend. This could include a
* reference to your public URL.
*
* @example
* ```js
* export default {
* publicRuntimeConfig: {
* baseURL: process.env.BASE_URL || 'https://nuxtjs.org'
* }
* }
* ```
* @version 2
* @version 3
*/
publicRuntimeConfig: {
app: {
$resolve: (val, get) => ({ ...get('app'), ...(val || {}) })
}
}
}