ElMassimo / vite_ruby

⚡️ Vite.js in Ruby, bringing joy to your JavaScript experience
https://vite-ruby.netlify.app/
MIT License
1.28k stars 117 forks source link

plugin_legacy is not working as expected #424

Open alexookah opened 9 months ago

alexookah commented 9 months ago

Description 📖

I am using ViteRails with ViteLegacy and it seems the plugin legacy is not working as expected. I am trying to use this config to provide replaceAll polyfill:

ViteLegacy({
  targets: ['Chrome 63'],
  modernPolyfills: ['es.string.replace', 'es.string.replace-all', 'esnext.string.replace-all'],  
  polyfills: ['es.string.replace', 'es.string.replace-all', 'esnext.string.replace-all']
}),

It seems that viteLegacy also adds some id's to provide correct polyfills support.

<script nomodule crossorigin id="vite-legacy-polyfill" src="/nested/vite/assets/polyfills-legacy-40tFIzrw.js"></script>
<script nomodule crossorigin id="vite-legacy-entry" data-src="/nested/vite/assets/index-legacy-TfDOTERY.js">System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))</script>

Is this PR maybe related? It's quite old PR but not sure why it was not never merged. (uses the 4.0 plugin-legacy version. Now there is version 5.0. Maybe it's needed to update for the latest version to support correct legacy same as the plugin legacy does?

Reproduction 🐞

Created an example repo https://github.com/alexookah/rails_example Added a simple test console.log with replaceAll https://github.com/alexookah/rails_example/blob/master/app/frontend/entrypoints/example_import.js

Screenshots 📷

Screenshot 2023-12-09 at 18 52 11

Screenshot 2023-12-09 at 18 52 00