-
Notifications
You must be signed in to change notification settings - Fork 108
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
Support for @vitejs/plugin-legacy #27
Comments
Hi Dominik! Thanks for the report. Fortunately, it's possible to replicate the same behavior that the plugin performs in the I'm about to release a new gem that includes these helpers. In the meantime, here's the code: # Public: Renders the vite-legacy-polyfill to enable code splitting in
# browsers that do not support modules.
def vite_legacy_polyfills_tag
return if ViteRuby.instance.dev_server_running?
name = vite_manifest.send(:manifest).keys.find { |file| file.include?('legacy-polyfills') } ||
raise(ArgumentError, 'Vite legacy polyfill not found in manifest.json')
tag.script(nomodule: true, src: vite_asset_path(name))
end
# Public: Renders a <script> tag for the specified Vite entrypoints when using
# @vitejs/plugin-legacy, which injects polyfills.
def vite_legacy_javascript_tag(name, asset_type: :javascript)
return if ViteRuby.instance.dev_server_running?
legacy_name = name.sub(/\.|$/, '-legacy\1')
id = "vite-#{ legacy_name.tr(' .\'', '-') }-entry"
legacy_tag = tag.script(nomodule: true, id: id, 'data-src': vite_asset_path(legacy_name, type: asset_type)) {
"System.import(document.getElementById('#{ id }').getAttribute('data-src'))".html_safe
}
safe_join [vite_legacy_polyfills_tag, legacy_tag]
end and then use it as: <body>
<%= yield %>
<%= vite_legacy_javascript_tag 'application' %>
</body>
</html> |
Gotcha, I was testing on Rails 5. Replace it with a |
I think |
Sorry, testing leftovers, thanks for the heads up! Please install There's a new section in the guide. I decided to skip the Safari 10 polyfill, but we could add a note in the docs so that anyone that needs to provide support for it knows what to do about it. |
We don't support Safari 10, so I agree, that it is not necessary. Thanks a lot for such a fast response with a solution! Great project btw! |
Tested, and I think this line should be
|
Sorry again! The require isn't necessary anymore as I used Released as |
Hi again! I think we have the last leftover. I am testing TypeScript in the project and
|
Didn't add a It might be useful to add that helper in a future release. Please try it out and let me know how it goes. |
Thanks, it worked :) |
Added |
Is your feature request related to a problem? Please describe.
In my RoR project support for older browsers (not supporting ES modules) is required. There is a great plugin from the Vite contributors - @vitejs/plugin-legacy - to support that case.
Unfortunately, it does not work properly with
vite_rails_legacy
(I did not check thevite_rails
). Themanifest.json
does not include additional chunks generated by the plugin, which are required to make it work properly.For now, I added the following code to the application layout:
The
application-legacy
chunk is generated, but not the rest.Describe the solution you'd like
I looked into the source code of the plugin, and it looks, that we should have also a list of chunks.
EDIT:
I bootstraped vite on node, and legacy plugin generates more sophisticated output (regardless of Safari 10 bugfix):
I am not sure how it can be integrated with this tool (as just output chunks will not be sufficient).
Describe alternatives you've considered
n/a.
The text was updated successfully, but these errors were encountered: