framework icon indicating copy to clipboard operation
framework copied to clipboard

feat(nuxt): `app.config` with hmr and reactivity support

Open pi0 opened this issue 3 years ago • 1 comments

🔗 Linked issue

Closes #5918

❓ Type of change

  • [ ] 📖 Documentation (updates to the documentation or readme)
  • [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [x] 👌 Enhancement (improving an existing functionality like performance)
  • [ ] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR adds support for (multi layer) app.config file with true HMR support and reactivity/editable on both client and server side.

A diversion from the original proposal is that I've decided to keep it separated from runtimeConfig at least for now since runtime config is globally frozen on server side and injection method of appConfig is foundomantelay different (bundler vs nitro-provided). This means appConfig and runtimeConfig.app are not the same.

Playground is edited to try new feature.

TODO:

  • [x] Working Vite HMR (*)
  • [x] Test Webpack HMR
  • [x] ~~Test deep assign~~ (seems not required)
  • [x] appConfig in nuxt.config for type support and easy module integration
  • [x] Programmatic way to add additional app.config files (possible by modifying appConfig or app:resolve hook)
  • [x] Add tests
  • [ ] ~~Inject $appConfig~~ (A plugin can easily inject reactive shortcut. Delagating addition to next steps)
  • [ ] Infer types from app.config for useAppConfig()

(*) When testing, I've found that virtual files do not support HMR

📝 Checklist

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

pi0 avatar Aug 03 '22 13:08 pi0

Deploy Preview for nuxt3-docs canceled.

Name Link
Latest commit 15f5e3f4d7ce8ac362639296ccee31bc1ed91db7
Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62fd05d478de67000842429f

netlify[bot] avatar Aug 03 '22 13:08 netlify[bot]

It would be nice to also test it in https://github.com/nuxt/framework/tree/main/examples/advanced/config-extends to check the multi layer support.

atinux avatar Aug 17 '22 09:08 atinux

@Atinux It is supported by default (main layer is part of other layers :))

pi0 avatar Aug 17 '22 09:08 pi0

HMR seems unstable with vite-node but is probably not directly related to this PR. We can test better on edge.

pi0 avatar Aug 17 '22 15:08 pi0