Handling Browser Compatibility in Vite

Use the official Vite legacy plugin to target older browsers without managing Browserslist/Core-JS manually.

Feb 7, 2025 · 1 min read · 79 Words · -Views -Comments · Programming
Build Tools 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Vite ships an official solution for legacy browser support.

Install the Plugin

npm install @vitejs/plugin-legacy

Configure

plugins: [
  // ... other plugins
  legacy({
    targets: [
      'defaults',
      'chrome >= 55',
      'safari >= 12',
      'not IE 11',
      'firefox >= 52',
    ],
  }),
]

The plugin simplifies compatibility—no need to fiddle with Browserslist or core-js directly.

Notes

  1. Because polyfills are injected based on targets, expect longer build times.
  2. Avoid configuring core-js manually; the plugin handles it.

Final Thoughts

That’s all—quick and clean.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover