This repository was archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(nuxt): app.config
with hmr and reactivity support
#6333
Merged
Merged
Changes from 26 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
5b8a04e
feat(nuxt): `app.config` with hmr support
pi0 eda4b99
Merge branch 'main' into feat/app-config
pi0 79ff3b1
webpack hmr support
pi0 c949684
update AppConfig schema
pi0 8316b5a
handle key removals
pi0 171d869
support inline config using `appConfig` in nuxt.config
pi0 22518d8
fix template when no appConfigs added
pi0 75e3be9
handle app.config add/removal
pi0 231e0ca
Merge branch 'main' into feat/app-config
pi0 efd22f0
auto generate types
pi0 3e0534c
add tests
pi0 8c2a012
Merge branch 'main' into feat/app-config
pi0 9cb0c74
fix test side effect
pi0 7d6c04a
Merge branch 'main' into feat/app-config
pi0 d3b9163
simplify reserved namespaces
pi0 9178cd8
fix: reserved are optional
pi0 bc269f3
Merge branch 'main' into feat/app-config
pi0 808bf9d
feat(nuxt): include type of resolved configs in AppConfig
danielroe d5011cf
refactor: write a single type declaration file
danielroe 5d9c593
chore: upgrade defu
danielroe 43b58f3
test: add type test
danielroe d152678
fix: update to use `Defu` type helper
danielroe 59ed668
fix: use `ResolvedAppConfig` to for type inference and extract `definβ¦
danielroe c63fd89
Merge branch 'main' into feat/app-config
pi0 69c5b50
try removing subpath from package.json
pi0 15ed77c
refactor: move `defineAppConfig` to `nuxt.ts`
pi0 f36e0d0
Update packages/nuxt/src/app/config.ts
pi0 df2380d
chore: fix ts issue
pi0 b2c7f57
remove unused import
pi0 a08d987
add usage to examples
pi0 6a571f5
add docs
pi0 e54db5d
fix vite hmr
pi0 2cace40
update docs
pi0 840f245
update api guide
pi0 ed0b584
revert useRuntimeConfig back to nuxt.ts
pi0 12ec374
Merge branch 'main' into feat/app-config
pi0 5e7d9c6
i touched it!
pi0 15f5e3f
strict is not funny
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,53 @@ | ||
import type { AppConfig, RuntimeConfig, AppConfigInput } from '@nuxt/schema' | ||
import { reactive } from 'vue' | ||
import { useNuxtApp } from './nuxt' | ||
// @ts-ignore | ||
import __appConfig from '#build/app.config.mjs' | ||
|
||
// Workaround for vite HMR with virtual modules | ||
export const _appConfig = __appConfig as AppConfig | ||
|
||
export function useRuntimeConfig (): RuntimeConfig { | ||
return useNuxtApp().$config | ||
} | ||
|
||
export function useAppConfig (): AppConfig { | ||
const nuxtApp = useNuxtApp() | ||
if (!nuxtApp._appConfig) { | ||
nuxtApp._appConfig = reactive(_appConfig) as AppConfig | ||
} | ||
return nuxtApp._appConfig | ||
} | ||
|
||
// HMR Support | ||
if (process.dev) { | ||
function applyHMR (newConfig: AppConfigInput) { | ||
pi0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const appConfig = useAppConfig() | ||
if (newConfig && appConfig) { | ||
for (const key in newConfig) { | ||
(appConfig as any)[key] = newConfig[key] | ||
} | ||
for (const key in appConfig) { | ||
if (!(key in newConfig)) { | ||
delete (appConfig as any)[key] | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Vite | ||
if (import.meta.hot) { | ||
import.meta.hot.accept((newModule) => { | ||
const newConfig = newModule?._appConfig | ||
applyHMR(newConfig) | ||
}) | ||
} | ||
|
||
// Webpack | ||
if (import.meta.webpackHot) { | ||
console.log('Register webpackHot') | ||
import.meta.webpackHot.accept('#build/app.config.mjs', () => { | ||
applyHMR(__appConfig) | ||
}) | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
export default defineAppConfig({ | ||
userConfig: 123, | ||
nested: { | ||
val: 2 | ||
} | ||
}) |
This file contains hidden or 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,3 @@ | ||
export default { | ||
fromLayer: true | ||
} |
This file contains hidden or 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 hidden or 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,11 @@ | ||
<template> | ||
<div> | ||
App Config: | ||
<!-- eslint-disable-next-line vue/no-v-html --> | ||
<pre v-html="JSON.stringify(appConfig)" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const appConfig = useAppConfig() | ||
</script> |
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.
Uh oh!
There was an error while loading. Please reload this page.