mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(vite): include import.meta
build vars in define
as well (#22576)
This commit is contained in:
parent
a88d3f3ccd
commit
758ae76709
@ -22,7 +22,9 @@ export default defineUntypedSchema({
|
|||||||
define: {
|
define: {
|
||||||
$resolve: async (val, get) => ({
|
$resolve: async (val, get) => ({
|
||||||
'process.dev': await get('dev'),
|
'process.dev': await get('dev'),
|
||||||
|
'import.meta.dev': await get('dev'),
|
||||||
'process.test': isTest,
|
'process.test': isTest,
|
||||||
|
'import.meta.test': isTest,
|
||||||
...val || {}
|
...val || {}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -44,6 +44,11 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
'process.browser': true,
|
'process.browser': true,
|
||||||
'process.nitro': false,
|
'process.nitro': false,
|
||||||
'process.prerender': false,
|
'process.prerender': false,
|
||||||
|
'import.meta.server': false,
|
||||||
|
'import.meta.client': true,
|
||||||
|
'import.meta.browser': true,
|
||||||
|
'import.meta.nitro': false,
|
||||||
|
'import.meta.prerender': false,
|
||||||
'module.hot': false
|
'module.hot': false
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
|
@ -43,6 +43,9 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
'process.server': true,
|
'process.server': true,
|
||||||
'process.client': false,
|
'process.client': false,
|
||||||
'process.browser': false,
|
'process.browser': false,
|
||||||
|
'import.meta.server': true,
|
||||||
|
'import.meta.client': false,
|
||||||
|
'import.meta.browser': false,
|
||||||
'typeof window': '"undefined"',
|
'typeof window': '"undefined"',
|
||||||
'typeof document': '"undefined"',
|
'typeof document': '"undefined"',
|
||||||
'typeof navigator': '"undefined"',
|
'typeof navigator': '"undefined"',
|
||||||
|
@ -145,7 +145,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
|
|||||||
nuxt.hook('vite:extendConfig', (config) => {
|
nuxt.hook('vite:extendConfig', (config) => {
|
||||||
config.plugins!.push(replace({
|
config.plugins!.push(replace({
|
||||||
preventAssignment: true,
|
preventAssignment: true,
|
||||||
...Object.fromEntries(Object.entries(config.define!).filter(([key]) => key.startsWith('process.')).map(([key, value]) => [key.replace('process.', 'import.meta.'), JSON.stringify(value)]))
|
...Object.fromEntries(Object.entries(config.define!).filter(([key]) => key.startsWith('import.meta.')))
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -4,9 +4,5 @@ export default defineVitestConfig({
|
|||||||
test: {
|
test: {
|
||||||
dir: './test/nuxt',
|
dir: './test/nuxt',
|
||||||
environment: 'nuxt'
|
environment: 'nuxt'
|
||||||
},
|
|
||||||
define: {
|
|
||||||
'import.meta.client': true,
|
|
||||||
'import.meta.server': false
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user