Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schema): warn if user provides vite.publicDir #21847

Merged

Conversation

NozomuIkuta
Copy link
Contributor

@NozomuIkuta NozomuIkuta commented Jun 28, 2023

πŸ”— Linked issue

Resolves #21831

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR is based on #21831 (comment)

I hope I'm doing it in right way and as @danielroe intended. πŸ™

References:

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@@ -30,6 +30,7 @@ export default defineUntypedSchema({
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
publicDir: {
$schema: { deprecated: 'use `dir.public` option instead' },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, is this used for documentation auto-generation and no influence on coding actual application code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, the message is quoted from dir.static option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I deprecate it at docs level, developers still can specify vite.publicDir option in Nuxt config file, because Nuxt accepts ViteConfig as vite option that extends/inherits all the properties from Vite's UserConfig.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's tricky. Setting $schema here won't have any effect, as you say, because it's being shadowed by ViteConfig. So instead we can set the deprecation on ViteConfig directly.

Comment on lines 176 to 180
nuxt.hook('vite:extendConfig', (config) => {
if (config.publicDir) {
consola.warn('Using `options.vite.publicDir` option is not supported together with Nuxt. Use `options.dir.public` instead. You can read more in `https://nuxt.com/docs/api/configuration/nuxt-config#public`.')
}
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (config.publicDir) {...} checks that config.publicDir !== false && config.publicDir !== '', both of which prevent public assets from being copied.

This warning message is shown twice in Terminal, because it's run for client build and server build. Should I show it only in either of them by checking isClient or isServer props?

Copy link
Member

@danielroe danielroe Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the warning to schema so it will only warn when user options are read in. what do you think?

Did this work previously? I would think it would always be set as Nuxt schema should always resolve the publicDir?

@danielroe danielroe changed the title chore(vite, schema): add warning for vite.publicDir option fix(schema): warn if user provides vite.publicDir Jul 5, 2023
@danielroe danielroe merged commit 381e0f8 into nuxt:main Jul 5, 2023
28 checks passed
@github-actions github-actions bot mentioned this pull request Jul 5, 2023
@NozomuIkuta
Copy link
Contributor Author

@danielroe

Oh, sorry I couldn't reply to your comments.
Thank you for refactoring my PR and merging it!

@NozomuIkuta NozomuIkuta deleted the chore/add-warning-for-vite-public-dir branch July 5, 2023 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to copy public folder when change dir.public
2 participants