diff --git a/packages/bridge/src/vite/client.ts b/packages/bridge/src/vite/client.ts index 810cb2f03e..d7787cb774 100644 --- a/packages/bridge/src/vite/client.ts +++ b/packages/bridge/src/vite/client.ts @@ -4,7 +4,6 @@ import { createVuePlugin } from 'vite-plugin-vue2' import PluginLegacy from '@vitejs/plugin-legacy' import consola from 'consola' import { jsxPlugin } from './plugins/jsx' -import { replace } from './plugins/replace' import { ViteBuildContext, ViteOptions } from './types' export async function buildClient (ctx: ViteBuildContext) { @@ -17,7 +16,11 @@ export async function buildClient (ctx: ViteBuildContext) { const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, { define: { - global: 'globalThis' + global: 'globalThis', + 'process.client': 'true', + 'process.server': 'false', + 'process.static': 'false', + 'module.hot': 'false' }, cacheDir: resolve(ctx.nuxt.options.rootDir, 'node_modules/.cache/vite/client'), resolve: { @@ -33,13 +36,6 @@ export async function buildClient (ctx: ViteBuildContext) { ssrManifest: true }, plugins: [ - replace({ - 'process.env': 'import.meta.env', - 'process.client': 'true', - 'process.server': 'false', - 'process.static': 'false', - 'module.hot': 'false' - }), jsxPlugin(), createVuePlugin(ctx.config.vue), PluginLegacy() diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index 30dbe49519..ca60c9c625 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -8,7 +8,6 @@ import type { Connect } from 'vite' import { visualizer } from 'rollup-plugin-visualizer' import { transform } from 'esbuild' import { cacheDirPlugin } from './plugins/cache-dir' -import { replace } from './plugins/replace' import { wpfs } from './utils/wpfs' import type { ViteBuildContext, ViteOptions } from './vite' import { writeManifest } from './manifest' @@ -37,7 +36,6 @@ export async function buildClient (ctx: ViteBuildContext) { outDir: resolve(ctx.nuxt.options.buildDir, 'dist/client') }, plugins: [ - replace({ 'process.env': 'import.meta.env' }), cacheDirPlugin(ctx.nuxt.options.rootDir, 'client'), vuePlugin(ctx.config.vue), viteJsxPlugin() diff --git a/packages/vite/src/plugins/replace.ts b/packages/vite/src/plugins/replace.ts deleted file mode 100644 index 986b9c95bc..0000000000 --- a/packages/vite/src/plugins/replace.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Plugin } from 'vite' - -export function replace (replacements: Record) { - return { - name: 'nuxt:replace', - transform (code) { - Object.entries(replacements).forEach(([key, value]) => { - const escapedKey = key.replace(/\./g, '\\.') - code = code.replace(new RegExp(escapedKey, 'g'), value) - }) - return { - code, - map: null - } - } - } -}