Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use @rollup/plugin-replace to replace define variables #9

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/pluginutils": "^5.0.5",
"@types/escape-html": "^1.0.3",
"@types/pnpapi": "^0.0.4",
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'node:path'
import { promisify } from 'node:util'
import { performance } from 'node:perf_hooks'
import type { RollupOutput } from 'rollup'
import rollupPluginReplace from '@rollup/plugin-replace'
import rollup from 'rollup'
import colors from 'picocolors'
import type { BuildOptions as EsbuildBuildOptions } from 'esbuild'
Expand All @@ -30,6 +31,7 @@ import {
import { transformWithEsbuild } from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET } from '../constants'
import { Rollup } from '..'
import { definePlugin } from '../plugins/define'
import { rollupCjsExternalPlugin, rollupDepPlugin } from './esbuildDepPlugin'
import { scanImports } from './scan'
import { createOptimizeDepsIncludeResolver, expandGlobIds } from './resolve'
Expand Down Expand Up @@ -751,8 +753,7 @@ async function prepareRollupOptimizerRun(

if (optimizerContext.cancelled) return { build: undefined, idToExports }

// esbuild automatically replaces process.env.NODE_ENV for platform 'browser'
// But in lib mode, we need to keep process.env.NODE_ENV untouched
// In lib mode, we need to keep process.env.NODE_ENV untouched
const define = {
'process.env.NODE_ENV':
isBuild && config.build.lib
Expand Down Expand Up @@ -792,6 +793,7 @@ async function prepareRollupOptimizerRun(
plugins.push(rollupCjsExternalPlugin(external, platform))
}
plugins.push(rollupDepPlugin(flatIdDeps, external, config, ssr))
plugins.push(rollupPluginReplace(define))

async function build() {
// TODO platform target define
Expand Down
44 changes: 44 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading