Skip to content

Commit 2dfd31d

Browse files
committed
fix: generate files in dist directory if not otherwise configured
resolves #363
1 parent 2c43bbb commit 2dfd31d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/module.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,22 @@ export default defineNuxtModule<ModuleOptions>({
156156
)
157157

158158
if (nuxt.options._generate) {
159-
nuxt.hook('nitro:config', config => {
159+
nuxt.hook('nitro:config', async config => {
160160
config.prerender ||= {}
161161
config.prerender.routes ||= []
162162
config.prerender.routes.push('/200.html')
163+
164+
config.output ||= {}
165+
if (!config.output.publicDir) {
166+
const distDir = resolve(nuxt.options.rootDir, 'dist')
167+
const stats = await fsp.lstat(distDir).catch(() => null)
168+
if (!stats || !stats.isSymbolicLink()) {
169+
config.output.publicDir = distDir
170+
if (!existsSync(distDir)) {
171+
await fsp.mkdir(distDir, { recursive: true })
172+
}
173+
}
174+
}
163175
})
164176

165177
// Ensure there is an index.html file present when doing static file generation

0 commit comments

Comments
 (0)