Skip to content

Commit ce0bb84

Browse files
committed
change database build dir
fixes compatibility with latest nuxt versions
1 parent 34f75c1 commit ce0bb84

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/module.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ export default defineNuxtModule({
3434

3535
const isDev = nuxt.options.dev
3636
const srcDir = nuxt.options.srcDir
37-
const pubPath = nuxt.options.app.buildAssetsDir
3837
const baseURL = nuxt.options.app.baseURL
3938

40-
const dbFolder = join('.', pubPath, 'database')
41-
const buildDir = resolve(nuxt.options.buildDir, dbFolder)
42-
const pubDir = resolve(nuxt.options.buildDir, 'dist', 'client', dbFolder)
39+
const dbFolder = join('.', '_database')
40+
const baseDir = resolve(nuxt.options.buildDir, 'nuxt-db')
41+
const buildDir = resolve(baseDir, dbFolder)
4342
const database = new Database({ ...options, isDev, srcDir, buildDir })
4443

4544
database.hook('file:beforeInsert', item => {
@@ -59,7 +58,7 @@ export default defineNuxtModule({
5958
const dbHash = await database.toHash()
6059
const dbName = `db-${dbHash}.json`
6160
const dbUrl = joinURL(baseURL, dbFolder, dbName)
62-
const dbPath = resolve(pubDir, dbName)
61+
const dbPath = resolve(baseDir, dbFolder, dbName)
6362

6463
nuxt.options.runtimeConfig.db = { dbPath }
6564
nuxt.options.runtimeConfig.public.db = { dbUrl }
@@ -86,19 +85,22 @@ export default defineNuxtModule({
8685
})
8786

8887
nuxt.hook('database:file:updated', async () => {
89-
await database.save(pubDir, dbName)
88+
await database.save(buildDir, dbName)
9089
await updateTemplates({ filter: temp => /^nuxtdb-/.test(temp.filename) })
9190
})
9291

9392
nuxt.hook('build:done', async () => {
94-
await database.save(pubDir, dbName)
93+
await database.save(buildDir, dbName)
9594
})
9695

97-
nuxt.hook('nitro:generate', async ctx => {
98-
const dbPath = join(ctx.output.publicDir, dbFolder, dbName)
99-
nuxt.options.runtimeConfig.db.dbPath = dbPath
96+
nuxt.hook('nitro:config', async nitroConfig => {
97+
nitroConfig.publicAssets ||= []
98+
nitroConfig.publicAssets.push({ dir: baseDir })
99+
})
100100

101-
await database.save(pubDir, dbName)
101+
nuxt.hook('nitro:build:before', async ctx => {
102+
const dbPath = join(ctx.options.output.publicDir, dbFolder, dbName)
103+
nuxt.options.runtimeConfig.db.dbPath = dbPath
102104
})
103105

104106
nuxt.hook('close', async () => {

0 commit comments

Comments
 (0)