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

[Breaking Change] Put plugin-legacy logic inside Vite core, for simplicity & flexibility and avoiding future breaking changes #10858

Closed
4 tasks done
Tal500 opened this issue Nov 9, 2022 · 1 comment

Comments

@Tal500
Copy link
Contributor

Tal500 commented Nov 9, 2022

Description

If I understand correctly, since Vite must use terser for minification of legacy chunks (and not the esbuild one that do some issues), and Vite didn't want to introduce the terser dependency by default, we have that plugin-legacy is not embedded in Vite core.
But this is problematic, since the plugin-legacy isn't fully orthogonal from Vite core plugins (meaning that some plugins depends on plugin-legacy behavior), we may benefit from embedding this plugin as a core plugin, so we can modify its internal behaviour without the worry of breaking changes, without worrying to not be compatible with some plugin-legacy versions.

Suggested solution

To embed the plugin-legacy logic in Vite core, without introducing the terser dependency, I suggest to put all the logic of plugin-legacy inside an internal Vite core plugin, say:

// plugin-legacy-internal.ts
export interface LegacyConfig {
};
function pluginLegacyInternal(config: LegacyConfig) {
// ...
}

And then, the plugin-legacy will be a "dummy" package, containing the dependency to the terser package, together with the following typescript file:

// plugin-legacy-public.ts
import { pluginLegacyInternal, type LegacyConfig } from '/path/to/plugin-legacy-internal.ts';

export { type LegacyConfig, pluginLegacyInternal as pluginLegacy };
// ...
}

This way, we introduce the ability to have flexible changes in the logic of plugin-legacy, while keeping the user experience similar to what happens today.

I suggest this breaking change now, since Vite is working on the breaking version 4.0.

Alternative

No response

Additional context

As a proof of concept, this will make implementing #10383 very easy, while currently it feels you need to juggle with magic token strings and be extra careful to implement it right and safely!

Validations

@patak-dev
Copy link
Member

It isn't only about Terser, but also about the need for Babel. I think plugin-legacy living in its own package has served us well, even considering the issues you raise here.

Lets close this issue for the moment and try to rework the current coupling by exposing some of Vite's internal APIs or other config options so we also allow other implementations of plugin legacy in the future, for example using SWC.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants