npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@heicore/plugin-legacy

v1.3.3

Published

**Note: this plugin requires `vite@^2.0.0-beta.12`**.

Downloads

2

Readme

@vitejs/plugin-legacy npm

Note: this plugin requires vite@^2.0.0-beta.12.

Vite's default browser support baseline is Native ESM. This plugin provides support for legacy browsers that do not support native ESM.

By default, this plugin will:

  • Generate a corresponding legacy chunk for every chunk in the final bundle, transformed with @babel/preset-env and emitted as SystemJS modules (code splitting is still supported!).

  • Generate a polyfill chunk including SystemJS runtime, and any necessary polyfills determined by specified browser targets and actual usage in the bundle.

  • Inject <script nomodule> tags into generated HTML to conditionally load the polyfills and legacy bundle only in browsers without native ESM support.

  • Inject the import.meta.env.LEGACY env variable, which will only be true in the legacy production build, and false in all other cases. (requires vite@^2.0.0-beta.69)

Usage

// vite.config.js
import legacy from '@vitejs/plugin-legacy'

export default {
  plugins: [
    legacy({
      targets: ['defaults', 'not IE 11']
    })
  ]
}

Options

targets

polyfills

  • Type: boolean | string[]

  • Default: true

    By default, a polyfills chunk is generated based on the target browser ranges and actual usage in the final bundle (detected via @babel/preset-env's useBuiltIns: 'usage').

    Set to a list of strings to explicitly control which polyfills to include. See Polyfill Specifiers for details.

    Set to false to avoid generating polyfills and handle it yourself (will still generate legacy chunks with syntax transformations).

additionalLegacyPolyfills

  • Type: string[]

    Add custom imports to the legacy polyfills chunk. Since the usage-based polyfill detection only covers ES language features, it may be necessary to manually specify additional DOM API polyfills using this option.

    Note: if additional plyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.

ignoreBrowserslistConfig

  • Type: boolean

  • Default: false

    @babel/preset-env automatically detects browserslist config sources:

    • browserslist field in package.json
    • .browserslistrc file in cwd.

    Set to false to ignore these sources.

modernPolyfills

  • Type: boolean | string[]

  • Default: false

    Defaults to false. Enabling this option will generate a separate polyfills chunk for the modern build (targeting browsers with native ESM support).

    Set to a list of strings to explicitly control which polyfills to include. See Polyfill Specifiers for details.

    Note it is not recommended to use the true value (which uses auto-detection) because core-js@3 is very aggressive in polyfill inclusions due to all the bleeding edge features it supports. Even when targeting native ESM support, it injects 15kb of polyfills!

    If you don't have hard reliance on bleeding edge runtime features, it is not that hard to avoid having to use polyfills in the modern build altogether. Alternatively, consider using an on-demand service like Polyfill.io to only inject necessary polyfills based on actual browser user-agents (most modern browsers will need nothing!).

renderLegacyChunks

  • Type: boolean

  • Default: true

    Set to false to disable legacy chunks. This is only useful if you are using modernPolyfills, which essentially allows you to use this plugin for injecting polyfills to the modern build only:

    import legacy from '@vitejs/plugin-legacy'
    
    export default {
      plugins: [
        legacy({
          modernPolyfills: [
            /* ... */
          ],
          renderLegacyChunks: false
        })
      ]
    }

Polyfill Specifiers

Polyfill specifier strings for polyfills and modernPolyfills can be either of the following:

Example

import legacy from '@vitejs/plugin-legacy'

export default {
  plugins: [
    legacy({
      polyfills: ['es.promise.finally', 'es/map', 'es/set'],
      modernPolyfills: ['es.promise.finally']
    })
  ]
}

Content Security Policy

The legacy plugin requires inline scripts for Safari 10.1 nomodule fix and SystemJS initialization. If you have a strict CSP policy requirement, you will need to add the corresponding hashes to your script-src list:

  • MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=
  • tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=

These values can also be retrived via

const { cspHashes } = require('@vitejs/plugin-legacy')

References