bfanger / tvkit

Proxy to run a modern dev server in old browsers
MIT License
22 stars 5 forks source link

Can this project be a Vite plugin/PR? #5

Closed Tal500 closed 1 year ago

Tal500 commented 1 year ago

This is Tal from SvelteKit legacy PR you were commenting on.

This project introduce a support for Vite in legacy mode during a "Dev server".

Can you try to make a Vite PR or plugin so this logic will work more generally in the Vite community?

bfanger commented 1 year ago

Although this project contains some SvelteKit specific code, the logic already works for other Vite projects too.

@vitejs/plugin-legacy is the plugin when it comes to supporting older browsers, hopefully this project inspires them to implement support for the dev server (and fix the struggles it has with custom setup's like SvelteKit)

I like the idea of an vite plugin. Maybe it could sit on top of the http requests, else it could be a convenient way to configure and start de proxy server.

// vite.config.ts
import { sveltekit } from "@sveltejs/kit/vite";
import tvkit from "tvkit/vite";
import type { UserConfig } from "vite";

const config: UserConfig = {
  plugins: [sveltekit(), tvkit({ target: "tizen 2016", port: 3000 })]
};

export default config;
Tal500 commented 1 year ago

Your project do two things:

  1. Be a middleman between the Vite dev server and the client.
  2. For static production output, it post-process Svelte output to inject the correct polyfills and legacy builds.

I believe(and probably you too) that while your project gives a support for nowadays users, the design isn't ideal(tough maybe optimal for now).

@vitejs/plugin-legacy is the plugin when it comes to supporting older browsers, hopefully this project inspires them to implement support for the dev server (and fix the struggles it has with custom setup's like SvelteKit)

I totally agree, the logic of supporting the Dev server should be part of plugin-legacy itself! We need to open an issue on Vite github page referencing this project, and maybe they will like the idea. Maybe we'll even make a PR to plugin-legacy following on your work.

I like the idea of an vite plugin. Maybe it could sit on top of the http requests, else it could be a convenient way to configure and start de proxy server.

I disagree about the way you say. Vite plugins are not HTTP based, they just "modify the generated output by plugin stages" - a generalisation of the Rollup plugins(that in Rollup they processed by the build stages).

// vite.config.ts
import { sveltekit } from "@sveltejs/kit/vite";
import tvkit from "tvkit/vite";
import type { UserConfig } from "vite";

const config: UserConfig = {
  plugins: [sveltekit(), tvkit({ target: "tizen 2016", port: 3000 })]
};

export default config;

I believe that if we implement legacy on dev in Vite official plugin-legacy, we can simply just use my PR of SvelteKit (that hopefully will be merged someday), and then it will work as clean as it should be, no static/dynamic HTTP proxies or whatsoever.

What do you think?

bfanger commented 1 year ago

SvelteKit is a framework for the future of webdevelopment, your PR as it stands adds a testproject that ankers the project into the past.

I wouldn't merge it if I was maintaining SvelteKit, but I would like SvelteKit to be compatible with the @vitejs/legacy-plugin. But it that not going to happen, I'm ok if that responsibility falls onto the community (aka via tvkit or other projects).

Tal500 commented 1 year ago

See the discussion in vitejs/vite#12050. I wonder how you didn't face these issues that mentioned there.