CopyPasta
CopyPasta
NNuxt
Created by CopyPasta on 5/1/2024 in #❓・help
How to enable SSR for only select pages in Vercel
No description
1 replies
NNuxt
Created by CopyPasta on 4/24/2024 in #❓・help
Is there any way to build custom js files?
Basically I want to build src/sdk.ts to {output}/sdk.js. Sort of like library mode in vite. Currently I'm using this module I wrote to render an entry file
import { defineNuxtModule } from 'nuxt/kit'
import { type LibraryOptions, build } from 'vite'
import { unocss } from 'config/uno'

export default defineNuxtModule<LibraryOptions>({
meta: {
name: 'lib',
configKey: 'lib'
},

setup(lib, nuxt) {
if (!lib || !lib.entry)
return

const libDir = `${nuxt.options.buildDir}/libs`

nuxt.hook('nitro:config', (nitro) => {
nitro.publicAssets ||= []
nitro.publicAssets.push({
dir: libDir,
maxAge: 3600
})
})

nuxt.hook('nitro:build:before', async () => {
await build({
publicDir: false,
plugins: [
unocss()
],

build: {
lib,
outDir: libDir
}
})
})
}
})
import { defineNuxtModule } from 'nuxt/kit'
import { type LibraryOptions, build } from 'vite'
import { unocss } from 'config/uno'

export default defineNuxtModule<LibraryOptions>({
meta: {
name: 'lib',
configKey: 'lib'
},

setup(lib, nuxt) {
if (!lib || !lib.entry)
return

const libDir = `${nuxt.options.buildDir}/libs`

nuxt.hook('nitro:config', (nitro) => {
nitro.publicAssets ||= []
nitro.publicAssets.push({
dir: libDir,
maxAge: 3600
})
})

nuxt.hook('nitro:build:before', async () => {
await build({
publicDir: false,
plugins: [
unocss()
],

build: {
lib,
outDir: libDir
}
})
})
}
})
If there's any better way to do this please let me know. Thanks!
2 replies