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!