1
0
elk/modules/build-env.ts

32 lines
958 B
TypeScript
Raw Normal View History

import { createResolver, defineNuxtModule } from '@nuxt/kit'
2023-01-08 22:27:29 +09:00
import { isCI } from 'std-env'
import { getEnv, version } from '../config/env'
import type { BuildInfo } from '~/types'
const { resolve } = createResolver(import.meta.url)
export default defineNuxtModule({
meta: {
name: 'elk:build-env',
},
async setup(_options, nuxt) {
const { env, commit, branch } = await getEnv()
const buildInfo: BuildInfo = {
version,
time: +Date.now(),
commit,
branch,
env,
}
nuxt.options.runtimeConfig.public.env = env
nuxt.options.runtimeConfig.public.buildInfo = buildInfo
2023-01-09 20:12:43 +09:00
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || []
if (env === 'dev')
nuxt.options.nitro.publicAssets.unshift({ dir: resolve('../public-dev') })
else if (env === 'canary' || env === 'preview' || !isCI)
nuxt.options.nitro.publicAssets.unshift({ dir: resolve('../public-staging') })
},
})