Skip to content

Commit b1bbc5b

Browse files
authored
refactor(legacy): remove code for Vite 2 (#9640)
1 parent 301442b commit b1bbc5b

File tree

1 file changed

+23
-48
lines changed

1 file changed

+23
-48
lines changed

packages/plugin-legacy/src/index.ts

+23-48
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,29 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
159159
const legacyConfigPlugin: Plugin = {
160160
name: 'vite:legacy-config',
161161

162-
apply: 'build',
163-
config(config) {
164-
if (!config.build) {
165-
config.build = {}
162+
config(config, env) {
163+
if (env.command === 'build') {
164+
if (!config.build) {
165+
config.build = {}
166+
}
167+
168+
if (!config.build.cssTarget) {
169+
// Hint for esbuild that we are targeting legacy browsers when minifying CSS.
170+
// Full CSS compat table available at https://github.com/evanw/esbuild/blob/78e04680228cf989bdd7d471e02bbc2c8d345dc9/internal/compat/css_table.go
171+
// But note that only the `HexRGBA` feature affects the minify outcome.
172+
// HSL & rebeccapurple values will be minified away regardless the target.
173+
// So targeting `chrome61` suffices to fix the compatibility issue.
174+
config.build.cssTarget = 'chrome61'
175+
}
166176
}
167177

168-
if (!config.build.cssTarget) {
169-
// Hint for esbuild that we are targeting legacy browsers when minifying CSS.
170-
// Full CSS compat table available at https://github.com/evanw/esbuild/blob/78e04680228cf989bdd7d471e02bbc2c8d345dc9/internal/compat/css_table.go
171-
// But note that only the `HexRGBA` feature affects the minify outcome.
172-
// HSL & rebeccapurple values will be minified away regardless the target.
173-
// So targeting `chrome61` suffices to fix the compatibility issue.
174-
config.build.cssTarget = 'chrome61'
178+
return {
179+
define: {
180+
'import.meta.env.LEGACY':
181+
env.command === 'serve' || config.build?.ssr
182+
? false
183+
: legacyEnvVarMarker
184+
}
175185
}
176186
}
177187
}
@@ -547,41 +557,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
547557
}
548558
}
549559

550-
let envInjectionFailed = false
551-
const legacyEnvPlugin: Plugin = {
552-
name: 'vite:legacy-env',
553-
554-
config(config, env) {
555-
if (env) {
556-
return {
557-
define: {
558-
'import.meta.env.LEGACY':
559-
env.command === 'serve' || config.build?.ssr
560-
? false
561-
: legacyEnvVarMarker
562-
}
563-
}
564-
} else {
565-
envInjectionFailed = true
566-
}
567-
},
568-
569-
configResolved(config) {
570-
if (envInjectionFailed) {
571-
config.logger.warn(
572-
`[@vitejs/plugin-legacy] import.meta.env.LEGACY was not injected due ` +
573-
`to incompatible vite version (requires vite@^2.0.0-beta.69).`
574-
)
575-
}
576-
}
577-
}
578-
579-
return [
580-
legacyConfigPlugin,
581-
legacyGenerateBundlePlugin,
582-
legacyPostPlugin,
583-
legacyEnvPlugin
584-
]
560+
return [legacyConfigPlugin, legacyGenerateBundlePlugin, legacyPostPlugin]
585561
}
586562

587563
export async function detectPolyfills(
@@ -667,8 +643,7 @@ async function buildPolyfillChunk(
667643
},
668644
output: {
669645
format,
670-
entryFileNames: rollupOutputOptions.entryFileNames,
671-
manualChunks: undefined
646+
entryFileNames: rollupOutputOptions.entryFileNames
672647
}
673648
}
674649
}

0 commit comments

Comments
 (0)