Skip to content

Commit e27acd0

Browse files
committed
feat: frame Nuxt config inherits from shell
1 parent 93c4ab8 commit e27acd0

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

playground/stories/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export default defineNuxtConfig({
66
frameCwd: '../',
77
framePort: 3000,
88
},
9+
ssr: false,
910
})

src/module.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,46 @@ const _module: NuxtModule<NuxtStoriesOptions> = defineNuxtModule<NuxtStoriesOpti
183183
// Remove app CSS from the shell to prevent style pollution — inherited by the frame via extends
184184
nuxt.options.css = []
185185

186+
// Keys from the shell's nuxt config that must NOT be forwarded to the frame.
187+
// Everything else is inherited so that top-level options like `ssr`, `experimental`,
188+
// `app`, `vite`, etc. propagate automatically.
189+
const FRAME_EXCLUDED_CONFIG_KEYS = new Set([
190+
// Frame-incompatible or explicitly overridden below
191+
'moduleDependencies',
192+
'modules',
193+
'css',
194+
'extends',
195+
'theme',
196+
'rootDir',
197+
'srcDir',
198+
'buildDir',
199+
'workspaceDir',
200+
'stories',
201+
'pages',
202+
'nitro',
203+
// Nuxt internals
204+
'_layers',
205+
'_installedModules',
206+
'_modules',
207+
'_ignore',
208+
])
209+
210+
// Read the shell app's raw user config (first layer = the shell's own nuxt.config).
211+
// This gives us user-defined values before Nuxt merges in its defaults.
212+
const shellRawConfig = ((nuxt.options._layers as unknown as Array<{ config: Record<string, unknown> }>)[0]
213+
?.config ?? {}) as Record<string, unknown>
214+
215+
const frameInheritedLines = Object.entries(shellRawConfig)
216+
.filter(([key]) => !FRAME_EXCLUDED_CONFIG_KEYS.has(key))
217+
.flatMap(([key, value]) => {
218+
try {
219+
return [` ${key}: ${JSON.stringify(value)},`]
220+
} catch {
221+
// Skip values that are not JSON-serializable (functions, class instances, etc.)
222+
return []
223+
}
224+
})
225+
186226
// Clear old .nuxt cache so the frame picks up the new config on restart
187227
const frameCacheDir = path.join(frameTmpDir, '.nuxt')
188228
if (fs.existsSync(frameCacheDir)) {
@@ -194,6 +234,8 @@ const _module: NuxtModule<NuxtStoriesOptions> = defineNuxtModule<NuxtStoriesOpti
194234
frameTmpConfig,
195235
[
196236
`export default {`,
237+
// Inherited shell options first — explicit entries below override them
238+
...frameInheritedLines,
197239
` rootDir: ${JSON.stringify(frameTmpDir)},`,
198240
` extends: [${JSON.stringify(frameAbsCwd)}],`,
199241
` modules: [${JSON.stringify(moduleEntry)}],`,

0 commit comments

Comments
 (0)