mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +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: {
|
||||
$resolve: async (val, get) => ({
|
||||
'process.dev': await get('dev'),
|
||||
'import.meta.dev': await get('dev'),
|
||||
'process.test': isTest,
|
||||
'import.meta.test': isTest,
|
||||
...val || {}
|
||||
})
|
||||
},
|
||||
|
@ -44,6 +44,11 @@ export async function buildClient (ctx: ViteBuildContext) {
|
||||
'process.browser': true,
|
||||
'process.nitro': 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
|
||||
},
|
||||
optimizeDeps: {
|
||||
|
@ -43,6 +43,9 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
'process.server': true,
|
||||
'process.client': false,
|
||||
'process.browser': false,
|
||||
'import.meta.server': true,
|
||||
'import.meta.client': false,
|
||||
'import.meta.browser': false,
|
||||
'typeof window': '"undefined"',
|
||||
'typeof document': '"undefined"',
|
||||
'typeof navigator': '"undefined"',
|
||||
|
@ -145,7 +145,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
|
||||
nuxt.hook('vite:extendConfig', (config) => {
|
||||
config.plugins!.push(replace({
|
||||
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: {
|
||||
dir: './test/nuxt',
|
||||
environment: 'nuxt'
|
||||
},
|
||||
define: {
|
||||
'import.meta.client': true,
|
||||
'import.meta.server': false
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user