Nuxt/packages/kit/src/config/schema/_common.ts

162 lines
3.7 KiB
TypeScript
Raw Normal View History

import { join, resolve } from 'path'
import env from 'std-env'
import createRequire from 'create-require'
import { pascalCase } from 'scule'
import jiti from 'jiti'
export default {
rootDir: {
$resolve: val => typeof val === 'string' ? resolve(val) : process.cwd()
},
srcDir: {
$resolve: (val, get) => resolve(get('rootDir'), val || '.')
},
buildDir: {
$resolve: (val, get) => resolve(get('rootDir'), val || '.nuxt')
},
dev: Boolean(env.dev),
test: Boolean(env.test),
debug: undefined,
env: {
$resolve: (val) => {
val = { ...val }
for (const key in process.env) {
if (key.startsWith('NUXT_ENV_')) {
val[key] = process.env[key]
}
}
return val
}
},
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
}
},
target: {
$resolve: val => ['server', 'static'].includes(val) ? val : 'server'
},
ssr: true,
mode: {
$resolve: (val, get) => val || (get('ssr') ? 'spa' : 'universal'),
$schema: { deprecated: '`mode` option is deprecated' }
},
modern: undefined,
modules: [],
buildModules: [],
_modules: [],
globalName: {
$resolve: val => (typeof val === 'string' && /^[a-zA-Z]+$/.test(val)) ? val.toLocaleLowerCase() : 'nuxt'
},
globals: {
id: globalName => `__${globalName}`,
nuxt: globalName => `$${globalName}`,
context: globalName => `__${globalName.toUpperCase()}__`,
pluginPrefix: globalName => globalName,
readyCallback: globalName => `on${pascalCase(globalName)}Ready`,
loadedCallback: globalName => `_on${pascalCase(globalName)}Loaded`
},
serverMiddleware: {
$resolve: (val: any) => {
if (!val) {
return []
}
if (!Array.isArray(val)) {
return Object.entries(val).map(([path, handler]) => ({ path, handler }))
}
return val
}
},
modulesDir: {
$default: ['node_modules'],
2021-04-03 12:42:02 +00:00
$resolve: (val, get) => [].concat(
val.map(dir => resolve(get('rootDir'), dir)),
resolve(process.cwd(), 'node_modules')
)
},
dir: {
assets: 'assets',
app: 'app',
layouts: 'layouts',
middleware: 'middleware',
pages: 'pages',
static: 'static',
store: 'store'
},
extensions: {
$resolve: val => ['.js', '.mjs', '.ts', '.tsx', '.vue'].concat(val).filter(Boolean)
},
styleExtensions: ['.css', '.pcss', '.postcss', '.styl', '.stylus', '.scss', '.sass', '.less'],
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
})
},
ignoreOptions: undefined,
ignorePrefix: '-',
ignore: {
$resolve: (val, get) => [
'**/*.test.*',
'**/*.spec.*',
get('ignorePrefix') && `**/${get('ignorePrefix')}*.*`
].concat(val).filter(Boolean)
},
watch: {
$resolve: (val, get) => [].concat(val, get('_nuxtConfigFiles')).filter(Boolean)
},
watchers: {
rewatchOnRawEvents: undefined,
webpack: {
aggregateTimeout: 1000
},
chokidar: {
ignoreInitial: true
}
},
editor: undefined,
hooks: null,
privateRuntimeConfig: {},
publicRuntimeConfig: {
app: {
$resolve: (val, get) => ({ ...get('app'), ...(val || {}) })
}
}
}