Skip to content

Conversation

@DudaGod
Copy link
Member

@DudaGod DudaGod commented Nov 16, 2025

What is done:

Implement ability to remove vite-style imports with query parameters when parse .jsx and .tsx files in node. More info about these imports here - https://vite.dev/guide/assets#explicit-url-imports.

Problem reproduced when using vite-plugin-svgr - https://github.com/pd4d10/vite-plugin-svgr

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/gemini-testing/testplane@1169

commit: 5a0379e

"ts-node": ">=10.5.0"
},
"peerDependenciesMeta": {
"@babel/parser": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use @babel/parser because I can't implement a plugin for esbuild when use transformSync in order to remove vite-style imports. For swc I can implement it in Rust, but it won't be a complete solution.

In next major we should move to use only swc parser.

registerTransformHook(this.isWorker());

this._config = Config.create(config);
updateTransformHook(this._config);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need config in order to check if tests run in node env or in browser env

const isJsxOrTsx = extname === ".jsx" || extname === ".tsx";

if (!isJsxOrTsx) {
return code;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do nothing if file is not jsx or tsx

if (typeof source === "string") {
const extname = path.extname(source);

if (extname && extname.includes("?")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove only imports which has query symbol in extension name, like - file.svg?react

);
return code;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this file is not covered by tests, as it requires integration tests, but we do not have a ready infrastructure for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants