Handling Browser Compatibility in Vite

Handling Browser Compatibility in Vite

2月 7, 2025 · 1 分钟阅读时长 · 79 字 · -阅读 -评论

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.

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源