mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
perf(schema): avoid duplicate get
operations (#24734)
This commit is contained in:
parent
0c04dc094a
commit
24bedc5e56
@ -50,7 +50,10 @@ export default defineUntypedSchema({
|
|||||||
* It is normally not needed to configure this option.
|
* It is normally not needed to configure this option.
|
||||||
*/
|
*/
|
||||||
workspaceDir: {
|
workspaceDir: {
|
||||||
$resolve: async (val, get) => val ? resolve(await get('rootDir'), val) : await findWorkspaceDir(await get('rootDir')).catch(() => get('rootDir'))
|
$resolve: async (val, get) => {
|
||||||
|
const rootDir = await get('rootDir')
|
||||||
|
return val ? resolve(rootDir, val) : await findWorkspaceDir(rootDir).catch(() => rootDir)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -305,15 +308,21 @@ export default defineUntypedSchema({
|
|||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
*/
|
*/
|
||||||
alias: {
|
alias: {
|
||||||
$resolve: async (val, get) => ({
|
$resolve: async (val, get) => {
|
||||||
'~': await get('srcDir'),
|
const srcDir = await get('srcDir')
|
||||||
'@': await get('srcDir'),
|
const rootDir = await get('rootDir')
|
||||||
'~~': await get('rootDir'),
|
const dirAssets = await get('dir.assets')
|
||||||
'@@': await get('rootDir'),
|
const dirPublic = await get('dir.public')
|
||||||
[await get('dir.assets')]: join(await get('srcDir'), await get('dir.assets')),
|
return {
|
||||||
[await get('dir.public')]: join(await get('srcDir'), await get('dir.public')),
|
'~': srcDir,
|
||||||
...val
|
'@': srcDir,
|
||||||
})
|
'~~': rootDir,
|
||||||
|
'@@': rootDir,
|
||||||
|
[dirAssets]: join(srcDir, dirAssets),
|
||||||
|
[dirPublic]: join(srcDir, dirPublic),
|
||||||
|
...val
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -342,15 +351,19 @@ export default defineUntypedSchema({
|
|||||||
* inside the `ignore` array will be ignored in building.
|
* inside the `ignore` array will be ignored in building.
|
||||||
*/
|
*/
|
||||||
ignore: {
|
ignore: {
|
||||||
$resolve: async (val, get) => [
|
$resolve: async (val, get) => {
|
||||||
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
|
const rootDir = await get('rootDir')
|
||||||
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
|
const ignorePrefix = await get('ignorePrefix')
|
||||||
'**/*.d.{cts,mts,ts}', // ignore type declarations
|
return [
|
||||||
'**/.{pnpm-store,vercel,netlify,output,git,cache,data}',
|
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
|
||||||
relative(await get('rootDir'), await get('analyzeDir')),
|
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
|
||||||
relative(await get('rootDir'), await get('buildDir')),
|
'**/*.d.{cts,mts,ts}', // ignore type declarations
|
||||||
await get('ignorePrefix') && `**/${await get('ignorePrefix')}*.*`
|
'**/.{pnpm-store,vercel,netlify,output,git,cache,data}',
|
||||||
].concat(val).filter(Boolean)
|
relative(rootDir, await get('analyzeDir')),
|
||||||
|
relative(rootDir, await get('buildDir')),
|
||||||
|
ignorePrefix && `**/${ignorePrefix}*.*`
|
||||||
|
].concat(val).filter(Boolean)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -444,13 +457,14 @@ export default defineUntypedSchema({
|
|||||||
*/
|
*/
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
$resolve: async (val: RuntimeConfig, get) => {
|
$resolve: async (val: RuntimeConfig, get) => {
|
||||||
|
const app = await get('app')
|
||||||
provideFallbackValues(val)
|
provideFallbackValues(val)
|
||||||
return defu(val, {
|
return defu(val, {
|
||||||
public: {},
|
public: {},
|
||||||
app: {
|
app: {
|
||||||
baseURL: (await get('app')).baseURL,
|
baseURL: app.baseURL,
|
||||||
buildAssetsDir: (await get('app')).buildAssetsDir,
|
buildAssetsDir: app.buildAssetsDir,
|
||||||
cdnURL: (await get('app')).cdnURL
|
cdnURL: app.cdnURL
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,16 @@ export default defineUntypedSchema({
|
|||||||
$resolve: async (val, get) => val ?? (await get('dev') ? 'development' : 'production')
|
$resolve: async (val, get) => val ?? (await get('dev') ? 'development' : 'production')
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
$resolve: async (val, get) => ({
|
$resolve: async (val, get) => {
|
||||||
'process.dev': await get('dev'),
|
const dev = await get('dev')
|
||||||
'import.meta.dev': await get('dev'),
|
return {
|
||||||
'process.test': isTest,
|
'process.dev': dev,
|
||||||
'import.meta.test': isTest,
|
'import.meta.dev': dev,
|
||||||
...val
|
'process.test': isTest,
|
||||||
})
|
'import.meta.test': isTest,
|
||||||
|
...val
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
||||||
|
Loading…
Reference in New Issue
Block a user