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

additionalLegacyPolyfills option for plugin-legacy #1475

Closed
DreierF opened this issue Jan 10, 2021 · 1 comment
Closed

additionalLegacyPolyfills option for plugin-legacy #1475

DreierF opened this issue Jan 10, 2021 · 1 comment
Labels
enhancement New feature or request plugin: legacy

Comments

@DreierF
Copy link
Contributor

DreierF commented Jan 10, 2021

Is your feature request related to a problem? Please describe.

Our App unfortunately still has to support IE11. Besides the polyfills that core-js provides we also need some browser polyfills like formdata-polyfill, element-remove, eligrey-classlist.js, whatwg-fetch etc. that are only relevant for IE11. Therefore I'd like these to only be included/executed in IE11.

With Webpack we are currently using a separate entrypoint that only imports the necessary polyfills and adds a nomodule via webpack-nomodule-plugin to the entry in the final html's script tag for this entry.

My naive attempt when migrating this to vite was to just add a nomodule script into the index.html file, but it is not picked up (I guess because vite only considers script type="module")

<script nomodule src="/src/Polyfills.ts"></script>

Describe the solution you'd like
I would like to have an option additionalLegacyPolyfills in @vitejs/plugin-legacy where I can specify a set of npm packages that should be bundled into polyfills-legacy.js in addition to the automatically detected core-js polyfills that are needed to run the code:

export default {
  plugins: [
    legacy({
      additionalLegacyPolyfills: ['formdata-polyfill', 'element-remove', 'eligrey-classlist.js']
    })
  ]
}

Describe alternatives you've considered
Another option would be to just add support for nomodule script tags (see my initial attempt).

@yyx990803 yyx990803 added enhancement New feature or request plugin: legacy labels Jan 11, 2021
@DreierF
Copy link
Contributor Author

DreierF commented Jan 12, 2021

Wow, that was fast!
Thanks a lot Evan!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request plugin: legacy
Projects
None yet
Development

No branches or pull requests

2 participants