feat(nuxt): add versions to runtime nuxtApp (#19064)

This commit is contained in:
Daniel Roe 2023-03-01 15:08:23 +00:00 committed by GitHub
parent c35104c769
commit d4a75240ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 1 deletions

View File

@ -42,6 +42,8 @@ Note: this is an internal interface, and some properties might change until stab
const nuxtApp = {
vueApp, // the global Vue application: https://vuejs.org/api/application.html#application-api
versions, // an object containing Nuxt and Vue versions
// These let you call and add runtime NuxtApp hooks
// https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L18
hooks,

5
packages/nuxt/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare global {
const __NUXT_VERSION__: string
}
export {}

View File

@ -60,6 +60,7 @@ export interface NuxtSSRContext extends SSRContext {
interface _NuxtApp {
vueApp: App<Element>
globalName: string
versions: Record<string, string>
hooks: Hookable<RuntimeNuxtHooks>
hook: _NuxtApp['hooks']['hook']
@ -120,6 +121,10 @@ export function createNuxtApp (options: CreateOptions) {
const nuxtApp: NuxtApp = {
provide: undefined,
globalName: 'nuxt',
versions: {
get nuxt () { return __NUXT_VERSION__ },
get vue () { return nuxtApp.vueApp.version }
},
payload: reactive({
data: {},
state: {},

View File

@ -59,6 +59,7 @@ export async function bundle (nuxt: Nuxt) {
exclude: ['nuxt/app']
},
css: resolveCSSOptions(nuxt),
define: { __NUXT_VERSION__: JSON.stringify(nuxt._version) },
build: {
copyPublicDir: false,
rollupOptions: {

View File

@ -230,6 +230,7 @@ function getEnv (ctx: WebpackConfigContext) {
'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
'process.mode': JSON.stringify(ctx.config.mode),
'process.dev': options.dev,
__NUXT_VERSION__: JSON.stringify(ctx.nuxt._version),
'process.env.VUE_ENV': JSON.stringify(ctx.name),
'process.browser': ctx.isClient,
'process.client': ctx.isClient,

View File

@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(stats.server.totalBytes).toBeLessThan(92800)
expect(stats.server.totalBytes).toBeLessThan(92900)
const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(modules.totalBytes).toBeLessThan(2722000)