N
Nuxt10mo ago
scrongly

Modifying the .output directory after pre-rendering routes

Hey gang, I'm in the process of migrating a Nuxt 2 build that uses storyblok with a complex directory structure for the backend. The existing build runs some logic on the generate.done() hook that loops over the .dist folders and copies some of them into new folders depending on the path. I've got as far as fetching and pre-rendering all the routes from storyblok, but I've no idea how to edit them after the fact since Nuxt no longer has a generate() hook. Here's a shortened example of the current logic (Unfortunately I cannot create a working demo as this is Work work):
// in nuxt.config.js
export default {
hooks: {
generate: {
async done(builder) {
let srcDir = `${builder.nuxt.options.generate.dir}/work-with-us/`
let destDir = `${builder.nuxt.options.generate.dir}/`

if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true })
}

ncp(srcDir, destDir, function (err) {
if (err) {
return console.error(err)
}
})
}
}
}
}
// in nuxt.config.js
export default {
hooks: {
generate: {
async done(builder) {
let srcDir = `${builder.nuxt.options.generate.dir}/work-with-us/`
let destDir = `${builder.nuxt.options.generate.dir}/`

if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true })
}

ncp(srcDir, destDir, function (err) {
if (err) {
return console.error(err)
}
})
}
}
}
}
Hopefully you get the idea. How do I do something similar in Nuxt 3? I've scoured the docs but I'm not really sure what I'm looking for so I would be grateful for any nudge in the right direction!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server