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
proposal: support legacy build with AST traversal #2
Comments
The SystemJS mode was originally planned to be supported after researching @vitejs/plugin-legacy. Of course, I am looking forward to your PR. |
I have a question. What does vite-plugin-dynamic-base/src/index.ts Lines 40 to 41 in a92b84a
|
This is when I read vite's implementation of assets path. |
The current implementation of this plugin does only support the modern ESM target and not the legacy target (SystemJS). The challenge of supporting legacy target is that legacy build not only includes
base
as the prefix of importing module path, but also bundles CSS data containing absoluteurl()
references in JS chunks, which is not easy to replace by regex.My solution is doing it by AST traversal. SWC is a blazing fast library to process JS code. First use a unique placeholder for
base
like/__vite_base__/
. Then we can just find all string literals and replace them with expressions like"string1" + window.publicPath + "string2" + window.publicPath + "string3"
.Here is my locally patched version of this plugin, which implements this feature:
You can check the result on my website. I could create a PR If you consider this feature useful and accepts my solution.
The text was updated successfully, but these errors were encountered: