From 17f9c54a7913917c009c16e4e3f4cadb922aad4e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 13 May 2022 11:49:30 +0100 Subject: [PATCH] feat(vite): replace `global` with `globalThis` (#4958) --- packages/vite/package.json | 1 + packages/vite/src/vite.ts | 5 +++++ yarn.lock | 1 + 3 files changed, 7 insertions(+) diff --git a/packages/vite/package.json b/packages/vite/package.json index 83dadc43f7..4446c2b519 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -20,6 +20,7 @@ }, "dependencies": { "@nuxt/kit": "^3.0.0-rc.3", + "@rollup/plugin-replace": "^4.0.0", "@vitejs/plugin-vue": "^2.3.3", "@vitejs/plugin-vue-jsx": "^1.3.10", "autoprefixer": "^10.4.7", diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 552039c76d..6b5925510c 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -4,6 +4,7 @@ import type { Nuxt } from '@nuxt/schema' import type { InlineConfig, SSROptions } from 'vite' import { logger, isIgnored } from '@nuxt/kit' import type { Options } from '@vitejs/plugin-vue' +import replace from '@rollup/plugin-replace' import { sanitizeFilePath } from 'mlly' import { getPort } from 'get-port-please' import { buildClient } from './client' @@ -64,6 +65,10 @@ export async function bundle (nuxt: Nuxt) { } }, plugins: [ + replace({ + ...Object.fromEntries([';', '(', '{', '}', ' ', '\t', '\n'].map(d => [`${d}global.`, `${d}globalThis.`])), + preventAssignment: true + }), virtual(nuxt.vfs), DynamicBasePlugin.vite({ sourcemap: nuxt.options.sourcemap }) ], diff --git a/yarn.lock b/yarn.lock index 38cd64063c..1319162c48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1628,6 +1628,7 @@ __metadata: dependencies: "@nuxt/kit": ^3.0.0-rc.3 "@nuxt/schema": ^3.0.0-rc.3 + "@rollup/plugin-replace": ^4.0.0 "@types/cssnano": ^5 "@vitejs/plugin-vue": ^2.3.3 "@vitejs/plugin-vue-jsx": ^1.3.10