2018-03-16 19:11:24 +00:00
import path from 'path'
import fs from 'fs'
2020-12-22 17:07:50 +00:00
import { defaultsDeep , pick , uniq } from 'lodash'
2023-02-02 00:02:45 +00:00
import { defu } from 'defu'
2018-04-13 06:50:39 +00:00
import consola from 'consola'
2020-05-22 18:51:53 +00:00
import destr from 'destr'
2020-12-29 12:15:12 +00:00
import { TARGETS , MODES , createRequire , guardDir , isNonEmptyString , isPureObject , isUrl , getMainModule , getPKG } from '@nuxt/utils'
2021-03-10 11:48:41 +00:00
import { isRelative , joinURL , normalizeURL , withTrailingSlash } from 'ufo'
2019-01-22 19:52:43 +00:00
import { defaultNuxtConfigFile , getDefaultNuxtConfig } from './config'
2018-03-16 17:23:15 +00:00
2019-07-10 10:45:49 +00:00
export function getNuxtConfig ( _options ) {
2018-12-09 10:42:22 +00:00
// Prevent duplicate calls
if ( _options . _ _normalized _ _ ) {
return _options
}
2017-06-14 16:13:43 +00:00
// Clone options to prevent unwanted side-effects
const options = Object . assign ( { } , _options )
2018-12-09 10:42:22 +00:00
options . _ _normalized _ _ = true
2017-06-14 16:13:43 +00:00
// Normalize options
if ( options . loading === true ) {
delete options . loading
}
2019-04-05 14:15:58 +00:00
2018-01-13 05:22:11 +00:00
if (
options . router &&
options . router . middleware &&
! Array . isArray ( options . router . middleware )
) {
2017-06-14 16:13:43 +00:00
options . router . middleware = [ options . router . middleware ]
}
2019-04-05 14:15:58 +00:00
2017-06-14 16:13:43 +00:00
if ( options . router && typeof options . router . base === 'string' ) {
options . _routerBaseSpecified = true
}
2019-04-05 14:15:58 +00:00
2019-07-24 11:35:50 +00:00
// TODO: Remove for Nuxt 3
// router.scrollBehavior -> app/router.scrollBehavior.js
if ( options . router && typeof options . router . scrollBehavior !== 'undefined' ) {
consola . warn ( '`router.scrollBehavior` property is deprecated in favor of using `~/app/router.scrollBehavior.js` file, learn more: https://nuxtjs.org/api/configuration-router#scrollbehavior' )
}
2019-04-20 10:01:59 +00:00
// TODO: Remove for Nuxt 3
// transition -> pageTransition
if ( typeof options . transition !== 'undefined' ) {
consola . warn ( '`transition` property is deprecated in favor of `pageTransition` and will be removed in Nuxt 3' )
options . pageTransition = options . transition
delete options . transition
}
if ( typeof options . pageTransition === 'string' ) {
options . pageTransition = { name : options . pageTransition }
2017-06-14 16:13:43 +00:00
}
2019-04-05 14:15:58 +00:00
2017-09-08 10:42:00 +00:00
if ( typeof options . layoutTransition === 'string' ) {
options . layoutTransition = { name : options . layoutTransition }
}
2019-04-05 14:15:58 +00:00
2018-01-04 17:10:17 +00:00
if ( typeof options . extensions === 'string' ) {
2018-01-13 05:22:11 +00:00
options . extensions = [ options . extensions ]
2018-01-04 17:10:17 +00:00
}
2017-06-14 16:13:43 +00:00
2018-10-30 20:42:53 +00:00
options . globalName = ( isNonEmptyString ( options . globalName ) && /^[a-zA-Z]+$/ . test ( options . globalName ) )
2018-10-09 12:07:23 +00:00
? options . globalName . toLowerCase ( )
2019-11-27 19:51:48 +00:00
// use `` for preventing replacing to nuxt-edge
: ` nuxt `
2018-10-09 12:07:23 +00:00
2018-09-14 07:06:44 +00:00
// Resolve rootDir
2018-10-30 20:42:53 +00:00
options . rootDir = isNonEmptyString ( options . rootDir ) ? path . resolve ( options . rootDir ) : process . cwd ( )
2017-12-04 19:52:50 +00:00
// Apply defaults by ${buildDir}/dist/build.config.js
2017-12-13 02:17:44 +00:00
// TODO: Unsafe operation.
2018-03-16 17:23:15 +00:00
// const buildDir = options.buildDir || defaults.buildDir
2017-12-13 02:17:44 +00:00
// const buildConfig = resolve(options.rootDir, buildDir, 'build.config.js')
// if (existsSync(buildConfig)) {
2018-10-18 15:43:44 +00:00
// defaultsDeep(options, require(buildConfig))
2017-12-13 02:17:44 +00:00
// }
2017-06-14 16:13:43 +00:00
// Apply defaults
2018-10-30 20:42:53 +00:00
const nuxtConfig = getDefaultNuxtConfig ( )
2018-11-20 17:12:05 +00:00
2018-10-30 20:42:53 +00:00
nuxtConfig . build . _publicPath = nuxtConfig . build . publicPath
2018-11-20 17:12:05 +00:00
// Fall back to default if publicPath is falsy
if ( options . build && ! options . build . publicPath ) {
options . build . publicPath = undefined
}
2018-10-30 20:42:53 +00:00
defaultsDeep ( options , nuxtConfig )
2017-06-14 16:13:43 +00:00
2020-05-07 19:08:01 +00:00
// Target
options . target = options . target || 'server'
if ( ! Object . values ( TARGETS ) . includes ( options . target ) ) {
consola . warn ( ` Unknown target: ${ options . target } . Falling back to server ` )
options . target = 'server'
}
2020-09-09 14:39:20 +00:00
// Deprecate Mode
if ( options . mode ) {
if ( ( options . mode === MODES . universal && options . ssr ) || ( options . mode === MODES . spa && ! options . ssr ) ) {
consola . warn ( '`mode` option is deprecated. You can safely remove it from `nuxt.config`' )
} else {
consola . warn ( '`mode` option is deprecated. Please use `ssr: true` for universal mode or `ssr: false` for spa mode and remove `mode` from `nuxt.config`' )
}
} else {
// For backward compat we need default value
options . mode = MODES . universal
}
2020-05-07 19:08:01 +00:00
// SSR root option
if ( options . ssr === false ) {
options . mode = MODES . spa
}
// Apply mode preset
const modePreset = options . modes [ options . mode || MODES . universal ]
if ( ! modePreset ) {
consola . warn ( ` Unknown mode: ${ options . mode } . Falling back to ${ MODES . universal } ` )
}
defaultsDeep ( options , modePreset || options . modes [ MODES . universal ] )
2019-04-05 14:15:58 +00:00
// Sanitize router.base
2020-12-09 23:19:31 +00:00
options . router . base = withTrailingSlash ( normalizeURL ( options . router . base ) )
2019-04-05 14:15:58 +00:00
2020-07-16 15:10:54 +00:00
// Legacy support for export
2020-05-20 15:43:25 +00:00
if ( options . export ) {
2020-07-16 15:10:54 +00:00
consola . warn ( 'export option is deprecated and will be removed in a future version! Please switch to generate' )
2020-05-20 15:43:25 +00:00
options . generate = defu ( options . export , options . generate )
}
exports . export = options . generate
2018-12-12 06:31:49 +00:00
// Check srcDir and generate.dir existence
2018-10-30 20:42:53 +00:00
const hasSrcDir = isNonEmptyString ( options . srcDir )
const hasGenerateDir = isNonEmptyString ( options . generate . dir )
2018-09-14 07:06:44 +00:00
// Resolve srcDir
options . srcDir = hasSrcDir
2018-03-16 19:11:24 +00:00
? path . resolve ( options . rootDir , options . srcDir )
2018-01-13 05:22:11 +00:00
: options . rootDir
2018-09-14 07:06:44 +00:00
// Resolve buildDir
2018-03-16 19:11:24 +00:00
options . buildDir = path . resolve ( options . rootDir , options . buildDir )
2017-06-14 16:13:43 +00:00
2019-05-06 13:59:37 +00:00
// Aliases
const { rootDir , srcDir , dir : { assets : assetsDir , static : staticDir } } = options
options . alias = {
'~~' : rootDir ,
'@@' : rootDir ,
'~' : srcDir ,
'@' : srcDir ,
[ assetsDir ] : path . join ( srcDir , assetsDir ) ,
[ staticDir ] : path . join ( srcDir , staticDir ) ,
... options . alias
}
2018-12-09 10:42:22 +00:00
// Default value for _nuxtConfigFile
if ( ! options . _nuxtConfigFile ) {
2019-03-14 10:07:47 +00:00
options . _nuxtConfigFile = path . resolve ( options . rootDir , ` ${ defaultNuxtConfigFile } .js ` )
2018-12-09 10:42:22 +00:00
}
2019-04-11 10:04:21 +00:00
if ( ! options . _nuxtConfigFiles ) {
options . _nuxtConfigFiles = [
options . _nuxtConfigFile
]
}
// Watch for config file changes
options . watch . push ( ... options . _nuxtConfigFiles )
2018-12-09 10:42:22 +00:00
2018-09-14 07:06:44 +00:00
// Protect rootDir against buildDir
guardDir ( options , 'rootDir' , 'buildDir' )
if ( hasGenerateDir ) {
// Resolve generate.dir
options . generate . dir = path . resolve ( options . rootDir , options . generate . dir )
// Protect rootDir against buildDir
guardDir ( options , 'rootDir' , 'generate.dir' )
}
if ( hasSrcDir ) {
// Protect srcDir against buildDir
guardDir ( options , 'srcDir' , 'buildDir' )
if ( hasGenerateDir ) {
// Protect srcDir against generate.dir
guardDir ( options , 'srcDir' , 'generate.dir' )
}
}
2017-12-13 01:09:38 +00:00
// Populate modulesDir
2018-11-29 13:16:46 +00:00
options . modulesDir = uniq (
2019-01-14 20:31:39 +00:00
getMainModule ( ) . paths . concat (
2018-11-29 13:16:46 +00:00
[ ] . concat ( options . modulesDir ) . map ( dir => path . resolve ( options . rootDir , dir ) )
)
)
2017-12-12 12:57:01 +00:00
2019-07-24 07:26:44 +00:00
const mandatoryExtensions = [ 'js' , 'mjs' ]
2018-01-04 17:10:17 +00:00
2018-10-12 22:31:19 +00:00
options . extensions = mandatoryExtensions
. filter ( ext => ! options . extensions . includes ( ext ) )
. concat ( options . extensions )
2018-03-16 20:04:54 +00:00
2017-06-14 16:13:43 +00:00
// If app.html is defined, set the template path to the user template
2018-08-10 15:23:09 +00:00
if ( options . appTemplatePath === undefined ) {
options . appTemplatePath = path . resolve ( options . buildDir , 'views/app.template.html' )
if ( fs . existsSync ( path . join ( options . srcDir , 'app.html' ) ) ) {
options . appTemplatePath = path . join ( options . srcDir , 'app.html' )
}
} else {
options . appTemplatePath = path . resolve ( options . srcDir , options . appTemplatePath )
2017-06-14 16:13:43 +00:00
}
2018-11-20 17:12:05 +00:00
options . build . publicPath = options . build . publicPath . replace ( /([^/])$/ , '$1/' )
options . build . _publicPath = options . build . _publicPath . replace ( /([^/])$/ , '$1/' )
2017-06-14 17:32:25 +00:00
// Ignore publicPath on dev
if ( options . dev && isUrl ( options . build . publicPath ) ) {
2018-10-30 20:42:53 +00:00
options . build . publicPath = options . build . _publicPath
2017-06-14 17:32:25 +00:00
}
// If store defined, update store options to true unless explicitly disabled
2018-02-27 13:38:00 +00:00
if (
options . store !== false &&
2018-03-16 19:11:24 +00:00
fs . existsSync ( path . join ( options . srcDir , options . dir . store ) ) &&
fs . readdirSync ( path . join ( options . srcDir , options . dir . store ) )
2018-02-27 13:38:00 +00:00
. find ( filename => filename !== 'README.md' && filename [ 0 ] !== '.' )
) {
2017-06-14 17:38:07 +00:00
options . store = true
2017-06-14 17:32:25 +00:00
}
2018-03-20 09:13:36 +00:00
// SPA loadingIndicator
if ( options . loadingIndicator ) {
// Normalize loadingIndicator
if ( ! isPureObject ( options . loadingIndicator ) ) {
options . loadingIndicator = { name : options . loadingIndicator }
}
// Apply defaults
options . loadingIndicator = Object . assign (
{
2018-03-25 18:35:13 +00:00
name : 'default' ,
2018-03-25 19:10:39 +00:00
color : ( options . loading && options . loading . color ) || '#D3D3D3' ,
2018-03-25 18:35:13 +00:00
color2 : '#F5F5F5' ,
2018-03-25 19:10:39 +00:00
background : ( options . manifest && options . manifest . theme _color ) || 'white' ,
2018-03-25 18:35:13 +00:00
dev : options . dev ,
loading : options . messages . loading
2018-03-20 09:13:36 +00:00
} ,
options . loadingIndicator
)
2017-08-18 10:26:19 +00:00
}
2018-01-10 16:36:32 +00:00
2018-03-21 06:20:14 +00:00
// Debug errors
if ( options . debug === undefined ) {
options . debug = options . dev
}
2019-09-20 18:49:16 +00:00
// Validate that etag.hash is a function, if not unset it
if ( options . render . etag ) {
const { hash } = options . render . etag
if ( hash ) {
const isFn = typeof hash === 'function'
if ( ! isFn ) {
options . render . etag . hash = undefined
if ( options . dev ) {
consola . warn ( ` render.etag.hash should be a function, received ${ typeof hash } instead ` )
}
}
}
}
2018-01-10 16:31:27 +00:00
// Apply default hash to CSP option
2019-04-01 19:59:58 +00:00
if ( options . render . csp ) {
2020-04-24 08:59:56 +00:00
options . render . csp = defu ( options . render . csp , {
2019-04-01 19:59:58 +00:00
hashAlgorithm : 'sha256' ,
allowedSources : undefined ,
policies : undefined ,
2020-05-07 19:08:01 +00:00
addMeta : Boolean ( options . target === TARGETS . static ) ,
2019-10-19 08:15:07 +00:00
unsafeInlineCompatibility : false ,
2019-04-01 19:59:58 +00:00
reportOnly : options . debug
} )
2019-10-19 08:15:07 +00:00
// TODO: Remove this if statement in Nuxt 3, we will stop supporting this typo (more on: https://github.com/nuxt/nuxt.js/pull/6583)
if ( options . render . csp . unsafeInlineCompatiblity ) {
consola . warn ( 'Using `unsafeInlineCompatiblity` is deprecated and will be removed in Nuxt 3. Use `unsafeInlineCompatibility` instead.' )
options . render . csp . unsafeInlineCompatibility = options . render . csp . unsafeInlineCompatiblity
delete options . render . csp . unsafeInlineCompatiblity
}
2018-01-10 16:31:27 +00:00
}
2017-08-18 10:26:19 +00:00
2017-08-20 08:38:38 +00:00
// cssSourceMap
if ( options . build . cssSourceMap === undefined ) {
options . build . cssSourceMap = options . dev
}
2018-11-08 20:47:53 +00:00
const babelConfig = options . build . babel
2018-03-09 06:30:50 +00:00
// babel cacheDirectory
2018-11-08 20:47:53 +00:00
if ( babelConfig . cacheDirectory === undefined ) {
babelConfig . cacheDirectory = options . dev
}
// TODO: remove this warn in Nuxt 3
if ( Array . isArray ( babelConfig . presets ) ) {
const warnPreset = ( presetName ) => {
const oldPreset = '@nuxtjs/babel-preset-app'
const newPreset = '@nuxt/babel-preset-app'
if ( presetName . includes ( oldPreset ) ) {
presetName = presetName . replace ( oldPreset , newPreset )
consola . warn ( '@nuxtjs/babel-preset-app has been deprecated, please use @nuxt/babel-preset-app.' )
}
return presetName
}
babelConfig . presets = babelConfig . presets . map ( ( preset ) => {
const hasOptions = Array . isArray ( preset )
if ( hasOptions ) {
preset [ 0 ] = warnPreset ( preset [ 0 ] )
} else if ( typeof preset === 'string' ) {
preset = warnPreset ( preset )
}
return preset
} )
2018-03-09 06:30:50 +00:00
}
2019-04-05 14:15:58 +00:00
// Vue config
2018-08-08 19:05:23 +00:00
const vueConfig = options . vue . config
if ( vueConfig . silent === undefined ) {
vueConfig . silent = ! options . dev
}
if ( vueConfig . performance === undefined ) {
vueConfig . performance = options . dev
}
2018-09-08 21:08:25 +00:00
// merge custom env with variables
2018-10-18 15:43:44 +00:00
const eligibleEnvVariables = pick ( process . env , Object . keys ( process . env ) . filter ( k => k . startsWith ( 'NUXT_ENV_' ) ) )
2018-09-08 21:08:25 +00:00
Object . assign ( options . env , eligibleEnvVariables )
2018-01-15 09:44:44 +00:00
// Normalize ignore
options . ignore = options . ignore ? [ ] . concat ( options . ignore ) : [ ]
// Append ignorePrefix glob to ignore
if ( typeof options . ignorePrefix === 'string' ) {
options . ignore . push ( ` **/ ${ options . ignorePrefix } *.* ` )
}
2018-09-08 20:18:14 +00:00
// Compression middleware legacy
if ( options . render . gzip ) {
2018-09-13 15:07:34 +00:00
consola . warn ( 'render.gzip is deprecated and will be removed in a future version! Please switch to render.compressor' )
2018-09-08 20:18:14 +00:00
options . render . compressor = options . render . gzip
delete options . render . gzip
}
2017-08-18 13:44:34 +00:00
// If no server-side rendering, add appear true transition
2019-04-20 10:01:59 +00:00
if ( options . render . ssr === false && options . pageTransition ) {
options . pageTransition . appear = true
2017-08-18 13:44:34 +00:00
}
2019-05-23 09:49:16 +00:00
options . render . ssrLog = options . dev
? options . render . ssrLog === undefined || options . render . ssrLog
: false
2018-01-27 00:20:03 +00:00
// We assume the SPA fallback path is 404.html (for GitHub Pages, Surge, etc.)
if ( options . generate . fallback === true ) {
options . generate . fallback = '404.html'
}
2018-08-12 12:39:43 +00:00
if ( options . build . stats === 'none' || options . build . quiet === true ) {
2018-03-29 07:11:34 +00:00
options . build . stats = false
}
2018-04-13 06:50:39 +00:00
// Vendor backward compatibility with nuxt 1.x
if ( typeof options . build . vendor !== 'undefined' ) {
delete options . build . vendor
consola . warn ( 'vendor has been deprecated due to webpack4 optimization' )
2018-04-12 20:42:50 +00:00
}
2019-02-13 10:32:13 +00:00
// Disable CSS extraction due to incompatibility with thread-loader
2019-03-05 17:07:05 +00:00
if ( options . build . extractCSS && options . build . parallel ) {
2019-02-13 10:32:13 +00:00
options . build . parallel = false
consola . warn ( 'extractCSS cannot work with parallel build due to limited work pool in thread-loader' )
}
2018-10-16 21:57:25 +00:00
// build.extractCSS.allChunks has no effect
if ( typeof options . build . extractCSS . allChunks !== 'undefined' ) {
consola . warn ( 'build.extractCSS.allChunks has no effect from v2.0.0. Please use build.optimization.splitChunks settings instead.' )
}
2019-08-09 10:32:53 +00:00
// devModules has been renamed to buildModules
if ( typeof options . devModules !== 'undefined' ) {
consola . warn ( '`devModules` has been renamed to `buildModules` and will be removed in Nuxt 3.' )
options . buildModules . push ( ... options . devModules )
delete options . devModules
}
2018-09-30 16:09:06 +00:00
// Enable minimize for production builds
if ( options . build . optimization . minimize === undefined ) {
options . build . optimization . minimize = ! options . dev
}
// Enable optimizeCSS only when extractCSS is enabled
if ( options . build . optimizeCSS === undefined ) {
options . build . optimizeCSS = options . build . extractCSS ? { } : false
}
2019-01-17 21:18:29 +00:00
const { loaders } = options . build
2018-09-10 08:27:01 +00:00
const vueLoader = loaders . vue
if ( vueLoader . productionMode === undefined ) {
vueLoader . productionMode = ! options . dev
}
const styleLoaders = [
'css' , 'cssModules' , 'less' ,
'sass' , 'scss' , 'stylus' , 'vueStyle'
]
for ( const name of styleLoaders ) {
const loader = loaders [ name ]
if ( loader && loader . sourceMap === undefined ) {
loader . sourceMap = Boolean ( options . build . cssSourceMap )
}
}
2018-07-31 13:10:24 +00:00
options . build . transpile = [ ] . concat ( options . build . transpile || [ ] )
2018-05-06 19:48:19 +00:00
2018-08-13 16:16:25 +00:00
if ( options . build . quiet === true ) {
consola . level = 0
}
2018-12-09 21:37:36 +00:00
// Use runInNewContext for dev mode by default
const { bundleRenderer } = options . render
if ( typeof bundleRenderer . runInNewContext === 'undefined' ) {
bundleRenderer . runInNewContext = options . dev
}
2020-04-07 09:38:49 +00:00
// TODO: Remove this if statement in Nuxt 3
if ( options . build . crossorigin ) {
consola . warn ( 'Using `build.crossorigin` is deprecated and will be removed in Nuxt 3. Please use `render.crossorigin` instead.' )
options . render . crossorigin = options . build . crossorigin
delete options . build . crossorigin
}
2023-02-06 22:59:12 +00:00
if ( options . build . postcss ? . plugins ) {
2023-02-02 15:13:28 +00:00
consola . warn ( '`postcss.plugins` option has been moved to `postcss.postcssOptions.plugins` for aligning `postcss-loader` format.' )
}
if ( options . buildModules && options . buildModules . includes ( '@nuxt/postcss8' ) ) {
consola . info ( '`@nuxt/postcss8` is disabled since nuxt has upgraded to postcss v8.' )
options . buildModules = options . buildModules . filter ( module => module !== '@nuxt/postcss8' )
}
2019-09-09 14:44:36 +00:00
const { timing } = options . server
if ( timing ) {
options . server . timing = { total : true , ... timing }
}
2019-09-29 09:11:25 +00:00
if ( isPureObject ( options . serverMiddleware ) ) {
options . serverMiddleware = Object . entries ( options . serverMiddleware )
2019-11-26 22:42:39 +00:00
. map ( ( [ path , handler ] ) => ( { path , handler } ) )
2019-09-29 09:11:25 +00:00
}
2020-12-22 17:15:59 +00:00
// App config (internal for nuxt2 at this stage)
const useCDN = isUrl ( options . build . publicPath ) && ! options . dev
2021-03-10 11:48:41 +00:00
const isRelativePublicPath = isRelative ( options . build . publicPath )
2020-12-22 17:15:59 +00:00
options . app = defu ( options . app , {
basePath : options . router . base ,
2021-03-10 11:48:41 +00:00
assetsPath : isRelativePublicPath ? options . build . publicPath : useCDN ? '/' : joinURL ( options . router . base , options . build . publicPath ) ,
2020-12-22 17:15:59 +00:00
cdnURL : useCDN ? options . build . publicPath : null
} )
2021-03-30 16:38:51 +00:00
// Expose app config to $config._app
2020-12-22 17:15:59 +00:00
options . publicRuntimeConfig = options . publicRuntimeConfig || { }
2021-03-30 16:38:51 +00:00
options . publicRuntimeConfig . _app = options . app
2020-12-22 17:15:59 +00:00
2020-05-07 19:08:01 +00:00
// Generate staticAssets
const { staticAssets } = options . generate
if ( ! staticAssets . version ) {
staticAssets . version = String ( Math . round ( Date . now ( ) / 1000 ) )
}
if ( ! staticAssets . base ) {
2020-12-22 17:15:59 +00:00
staticAssets . base = joinURL ( options . app . assetsPath , staticAssets . dir )
2020-05-07 19:08:01 +00:00
}
if ( ! staticAssets . versionBase ) {
2020-12-22 17:15:59 +00:00
staticAssets . versionBase = joinURL ( staticAssets . base , staticAssets . version )
2020-05-07 19:08:01 +00:00
}
2020-12-22 17:07:50 +00:00
// createRequire
const isJest = typeof jest !== 'undefined'
const defaultCreateRequire = isJest ? 'native' : 'jiti'
options . createRequire = process . env . NUXT _CREATE _REQUIRE || options . createRequire || defaultCreateRequire
2020-12-29 12:15:12 +00:00
if ( options . createRequire === 'native' || options . createRequire === 'jiti' ) {
const useJiti = options . createRequire === 'jiti'
options . createRequire = p => createRequire ( typeof p === 'string' ? p : p . filename , useJiti )
2020-06-11 13:59:13 +00:00
} else if ( typeof options . createRequire !== 'function' ) {
2020-12-22 17:07:50 +00:00
throw new TypeError (
` Unsupported createRequire value ${ options . createRequire } ! Possible values: "native", "jiti", <Function> `
)
2020-06-11 13:59:13 +00:00
}
2020-09-09 09:37:49 +00:00
// Indicator
// Change boolean true to default nuxt value
if ( options . build . indicator === true ) {
options . build . indicator = nuxtConfig . build . indicator
}
2020-06-03 19:34:10 +00:00
// ----- Builtin modules -----
// Loading screen
// Force disable for production and programmatic users
if ( ! options . dev || ! options . _cli || ! getPKG ( '@nuxt/loading-screen' ) ) {
options . build . loadingScreen = false
}
if ( options . build . loadingScreen ) {
options . _modules . push ( [ '@nuxt/loading-screen' , options . build . loadingScreen ] )
} else {
// When loadingScreen is disabled we should also disable build indicator
options . build . indicator = false
}
2023-02-20 20:28:43 +00:00
// Monkey patch crypto.createHash in dev/build to upgrade hashing fnction
2023-05-15 12:23:23 +00:00
if ( parseInt ( process . versions . node . slice ( 0 , 2 ) ) > 16 && ! options . buildModules . some ( m => m . name === 'patchMD4' ) ) {
2023-02-20 20:28:43 +00:00
options . buildModules . push ( function patchMD4 ( ) {
const crypto = require ( 'crypto' )
const _createHash = crypto . createHash
crypto . createHash = function ( algorithm , options ) {
return _createHash ( algorithm === 'md4' ? 'md5' : algorithm , options )
}
} )
}
2020-06-03 19:34:10 +00:00
// Components Module
if ( ! options . _start && getPKG ( '@nuxt/components' ) ) {
options . _modules . push ( '@nuxt/components' )
}
2020-05-22 18:51:53 +00:00
// Nuxt Telemetry
if (
options . telemetry !== false &&
! options . test &&
! destr ( process . env . NUXT _TELEMETRY _DISABLED ) &&
getPKG ( '@nuxt/telemetry' )
) {
2020-06-03 19:34:10 +00:00
options . _modules . push ( '@nuxt/telemetry' )
2020-05-22 18:51:53 +00:00
}
2017-06-14 16:13:43 +00:00
return options
}