-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(nuxt): resolve nitro config entries in layers (nuxt aliases) #26679
Draft
userquin
wants to merge
4
commits into
nuxt:main
Choose a base branch
from
userquin:fix-public-assets
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,10 +153,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { | |
maxAge: 31536000 /* 1 year */, | ||
baseURL: nuxt.options.app.buildAssetsDir, | ||
}, | ||
...nuxt.options._layers | ||
.map(layer => join(layer.config.srcDir, (layer.config.rootDir === nuxt.options.rootDir ? nuxt.options : layer.config).dir?.public || 'public')) | ||
.filter(dir => existsSync(dir)) | ||
.map(dir => ({ dir })), | ||
...(await resolvePublicFolders(nuxt)), | ||
], | ||
prerender: { | ||
failOnError: true, | ||
|
@@ -229,6 +226,8 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { | |
logLevel: logLevelMapReverse[nuxt.options.logLevel], | ||
} satisfies NitroConfig) | ||
|
||
await resolvePublicAssets(nuxt) | ||
|
||
// Resolve user-provided paths | ||
nitroConfig.srcDir = resolve(nuxt.options.rootDir, nuxt.options.srcDir, nitroConfig.srcDir!) | ||
nitroConfig.ignore = [...(nitroConfig.ignore || []), ...resolveIgnorePatterns(nitroConfig.srcDir), `!${join(nuxt.options.buildDir, 'dist/client', nuxt.options.app.buildAssetsDir)}/**/*`] | ||
|
@@ -594,3 +593,34 @@ async function spaLoadingTemplate (nuxt: Nuxt) { | |
|
||
return '' | ||
} | ||
|
||
async function resolvePublicFolders (nuxt: Nuxt) { | ||
const { dir: rootDir, srcDir, alias: rootAlias } = nuxt.options | ||
const dirs = await Promise.all(nuxt.options._layers.map((layer) => { | ||
const [path, cwd, alias] = layer.config.rootDir === nuxt.options.rootDir | ||
? [rootDir.public || 'public', srcDir, rootAlias] | ||
: [layer.config.dir?.public || 'public', layer.config.srcDir, layer.config.alias] | ||
return resolvePath(path, { cwd, alias: alias as Record<string, string> }) | ||
})) | ||
|
||
return dirs.filter(dir => existsSync(dir)).map(dir => ({ dir })) | ||
} | ||
|
||
async function resolvePublicAssets (nuxt: Nuxt) { | ||
const { dir: rootDir, srcDir, alias: rootAlias } = nuxt.options | ||
await Promise.all(nuxt.options._layers.map((layer) => { | ||
return Promise.all((layer.config.nitro?.publicAssets || []).map(async (publicAsset) => { | ||
if (!publicAsset) { | ||
return | ||
} | ||
const [path, cwd, alias] = layer.config.rootDir === nuxt.options.rootDir | ||
? [publicAsset.dir || rootDir.public || 'public', srcDir, rootAlias] | ||
: [publicAsset.dir || layer.config.dir?.public || 'public', layer.config.srcDir, layer.config.alias] | ||
const dir = await resolvePath(path, { cwd, alias: alias as Record<string, string> }) | ||
// TODO: should warn if missing? | ||
if (existsSync(dir)) { | ||
publicAsset.dir = dir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should warn or even throw? |
||
} | ||
})) | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
<img src="/subfolder/1x1.png"> | ||
</div> | ||
</template> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shold we use
!publicAssets?.dir
instead: if so, we should also remove|| rootDir.public || 'public'
from L617 and|| layer.config.dir?.public || 'public'
from L618There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've exluded
publicAssets
withoutdir