mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
refactor(nuxt): remove process.*
usage in nuxt vue app (#24749)
This commit is contained in:
parent
37a5d35a6d
commit
6c7d430845
1
packages/nuxt/index.d.ts
vendored
1
packages/nuxt/index.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
/* eslint-disable no-var */
|
||||
declare global {
|
||||
var __NUXT_VERSION__: string
|
||||
var __NUXT_ASYNC_CONTEXT__: boolean
|
||||
var __NUXT_PREPATHS__: string[] | string | undefined
|
||||
var __NUXT_PATHS__: string[] | string | undefined
|
||||
|
||||
|
@ -41,7 +41,7 @@ export function createClientOnly<T extends ComponentOptions> (component: T) {
|
||||
: h(res)
|
||||
} else {
|
||||
const fragment = getFragmentHTML(ctx._.vnode.el ?? null) ?? ['<div></div>']
|
||||
return process.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.$attrs ?? ctx._.attrs)
|
||||
return import.meta.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.$attrs ?? ctx._.attrs)
|
||||
}
|
||||
}
|
||||
} else if (clone.template) {
|
||||
@ -80,7 +80,7 @@ export function createClientOnly<T extends ComponentOptions> (component: T) {
|
||||
: h(res)
|
||||
} else {
|
||||
const fragment = getFragmentHTML(instance?.vnode.el ?? null) ?? ['<div></div>']
|
||||
return process.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.attrs)
|
||||
return import.meta.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.attrs)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -36,7 +36,7 @@ export function setResponseStatus (arg1: H3Event | number | undefined, arg2?: nu
|
||||
}
|
||||
|
||||
export function prerenderRoutes (path: string | string[]) {
|
||||
if (!process.server || !process.env.prerender) { return }
|
||||
if (!import.meta.server || !import.meta.prerender) { return }
|
||||
|
||||
const paths = Array.isArray(path) ? path : [path]
|
||||
appendHeader(useRequestEvent(), 'x-nitro-prerender', paths.map(p => encodeURIComponent(p)).join(', '))
|
||||
|
@ -19,7 +19,7 @@ import type { AsyncDataRequestStatus } from '../app/composables/asyncData'
|
||||
import type { NuxtAppManifestMeta } from '../app/composables/manifest'
|
||||
|
||||
const nuxtAppCtx = /*@__PURE__*/ getContext<NuxtApp>('nuxt-app', {
|
||||
asyncContext: !!process.env.NUXT_ASYNC_CONTEXT && process.server
|
||||
asyncContext: !!__NUXT_ASYNC_CONTEXT__ && import.meta.server
|
||||
})
|
||||
|
||||
type HookResult = Promise<void> | void
|
||||
|
@ -11,7 +11,7 @@ export default defineNuxtPlugin({
|
||||
name: 'nuxt:payload',
|
||||
setup (nuxtApp) {
|
||||
// TODO: Support dev
|
||||
if (process.dev) { return }
|
||||
if (import.meta.dev) { return }
|
||||
|
||||
// Load payload after middleware & once final route is resolved
|
||||
useRouter().beforeResolve(async (to, from) => {
|
||||
|
@ -62,7 +62,7 @@ export default defineNuxtModule({
|
||||
return 'export default []'
|
||||
}
|
||||
return `import { CapoPlugin } from ${JSON.stringify(unheadVue)};
|
||||
export default process.server ? [CapoPlugin({ track: true })] : [];`
|
||||
export default import.meta.server ? [CapoPlugin({ track: true })] : [];`
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -77,7 +77,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
|
||||
css: resolveCSSOptions(nuxt),
|
||||
define: {
|
||||
__NUXT_VERSION__: JSON.stringify(nuxt._version),
|
||||
'process.env.NUXT_ASYNC_CONTEXT': nuxt.options.experimental.asyncContext
|
||||
__NUXT_ASYNC_CONTEXT__: nuxt.options.experimental.asyncContext
|
||||
},
|
||||
build: {
|
||||
copyPublicDir: false,
|
||||
|
@ -217,8 +217,8 @@ function getEnv (ctx: WebpackConfigContext) {
|
||||
const _env: Record<string, string | boolean> = {
|
||||
'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
|
||||
__NUXT_VERSION__: JSON.stringify(ctx.nuxt._version),
|
||||
__NUXT_ASYNC_CONTEXT__: ctx.options.experimental.asyncContext,
|
||||
'process.env.VUE_ENV': JSON.stringify(ctx.name),
|
||||
'process.env.NUXT_ASYNC_CONTEXT': ctx.options.experimental.asyncContext,
|
||||
'process.dev': ctx.options.dev,
|
||||
'process.test': isTest,
|
||||
'process.browser': ctx.isClient,
|
||||
|
@ -11,9 +11,6 @@ export default defineConfig({
|
||||
'#app': resolve('./packages/nuxt/dist/app')
|
||||
}
|
||||
},
|
||||
define: {
|
||||
'process.env.NUXT_ASYNC_CONTEXT': 'false'
|
||||
},
|
||||
test: {
|
||||
globalSetup: './test/setup.ts',
|
||||
setupFiles: ['./test/setup-env.ts'],
|
||||
|
Loading…
Reference in New Issue
Block a user