nuxt-run
v1.2.0
Published
Bundle server run scripts into standalone mjs entries during the Nuxt/Nitro build
Readme
nuxt-run
Sponsored by
Runnable scripts in any environment.
Useful when you need to:
- Run service code against an environment without pulling secrets down
- Avoid HTTP endpoints just to trigger server code
- Skip a queue when a one-shot or cron script is enough
Getting started
npm install -D nuxt-run// nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-run'],
run: {
runDir: 'server/run',
runPattern: '**/index.{ts,js,mjs}',
},
})Add a script under server/run/<name>/index.ts:
// server/run/seed/index.ts
const {
database: {
url,
},
} = useRuntimeConfig()
const orm = new MyOrm(url)
const seed = async () => {
await orm.insert(...)
}
seed().catch((e) => {
console.error(e)
process.exit(1)
})In dev:
nuxt dev
node .nuxt/dev/run/seed/index.mjsPost build:
nuxt build
node .output/server/run/seed/index.mjsScripts share Nitro's module graph, so useRuntimeConfig() and server/utils work.
More detail: Getting started.
Contribution
npm install
npm run dev:prepare # generate type stubs
npm run dev # develop with the playground
npm run dev:build # production build of the playground
npm run lint
npm run test
npm run vp:dev # VitePress docs site
npm run release