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

@vitejs/plugin-legacy can not inject legacy "nomodule" scripts #7695

Closed
1 task
mschoeffmann opened this issue Jul 18, 2023 · 3 comments
Closed
1 task

@vitejs/plugin-legacy can not inject legacy "nomodule" scripts #7695

mschoeffmann opened this issue Jul 18, 2023 · 3 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@mschoeffmann
Copy link

What version of astro are you using?

2.8.3

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Mac

What browser are you using?

Chrome (latest), Safari (latest)

Describe the Bug

I am currently converting some projects from hugo to astro.
In my build pipeline, I want to prepare the static websites also for some older browsers (Safari 10, for example, which does not support async functions).

Now I wanted to archive the same result with astro and the help of @vitejs/plugin-legacy. But unfortunately this way is not working.

@vitejs/plugin-legacy is already creating the correct files for this. But they are not inserted into generated HTML pages.

To be clear: I DO NOT want to use astro specific features (islands) on old browsers. I'm talking about a few scripts without big frameworks. For example to automatically convert the ?. operator and so on ...

I am aware that astro is not planning to support "the whole big thing" to be compatible with old browsers. Modern techniques require modern browsers. Sure. This has been stated at #6096 and I agree. As I said: I'm talking about beeing able to have a build pipeline outputting compatible versions of a few scripts for old browsers.

What's the expected result?

To have the correct @vitejs/plugin-legacy scripts inserted on build time.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-7equ4f?file=README.md

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jul 18, 2023
@natemoo-re
Copy link
Member

natemoo-re commented Jul 18, 2023

This seems like a reasonable request.

The reason this isn't working automatically is because Astro does not currently support Vite's transformIndexHtml hook.

I'm not sure if there's a quick fix at the moment, but it could be something we can investigate. Unfortunately we can't expose the full html to the plugin, but we could (in theory) support the { tag, attrs, children }[] format.

@natemoo-re natemoo-re added the - P2: nice to have Not breaking anything but nice to have (priority) label Jul 18, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Jul 18, 2023
@bluwy
Copy link
Member

bluwy commented Dec 26, 2023

Another note: transformIndexHtml can only work for prerendered pages. In SSR, you can't bundle the Vite plugins to execute its transformIndexHtml hooks. Which means there's a risk that the pages could be inconsistent depending on the configuration that I'm not sure if this is something we want to support.

Currently @vitejs/plugin-legacy doesn't support many metaframeworks because of this, but maybe there's a different way we can make legacy to work.

@matthewp
Copy link
Contributor

Closing as this is an issue regarding how @vitejs/plugin-legacy works, it's only intended to be used in Vite, non-metaframework projects. Since there's nothing we can do on our side, there's no reason to keep the issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

4 participants