-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow arbitrary comments within dynamic imports and constructor calls #2721
Comments
What are the specific syntax and semantics of For example, Webpack comments follow the regular expression |
We currently don't have them documented unfortunately but only from warnings generated because of something Vite can't analyze. They can be used like in these examples: // comment should appear anywhere within the parentheses:
import(/* @vite-ignore */ dynamicVar)
import(dynamicVar /* @vite-ignore */) // it's rare someone does this, but works
// comment should appear within the second parameter, between `,` and `)`
new Worker(new URL('./path', import.meta.url), /* @vite-ignore */ dynamicOptions)
new Worker(new URL('./path', import.meta.url), dynamicOptions /* @vite-ignore */) // also rare someone does this, but works We're using this regex: |
Based on your comment, it sounds like a simple single rule to handle the |
I think to be accurate, it should be anywhere within the parameter boundary, so for cases like: import(/* @vite-ignore */ dynamicVar, { assert: { type: "json" } }) You could move it till the comma only: import(dynamicVar /* @vite-ignore */, { assert: { type: "json" } }) |
Actually it looks like you're right! Vite does capture the comment until the closing |
This was changed in fdf184e What is the benefice of preserving only Webpack comments when minify is off? |
That commit was added to fix a bug where Webpack comments were not being preserved if they weren't in the leading position.
This behavior only exists to support Webpack-specific comments in |
Would it be possible to keep other leading comments inside imports or add |
Yes, that's what this issue is about (making this work for Vite's magic comments as well). |
Bundle minification has been enabled because a change in eslint (evanw/esbuild#2721) means some comments are now preserved in the bundle, which isn't useful in the bundle generated for the UI. Minification prevents this.
Background
esbuild
currently supports special webpack comments withinimport()
andnew Worker()
(recently supported). Vite also supports special/* @vite-ignore */
comments but esbuild currently strips them out, causing Vite warnings in ts, jsx, tsx files.We're also experimenting with using esbuild for define replacements only which we found this issue: vitejs/vite#11151
Feature request
It would be nice to allow arbitrary comments within
import()
andnew Worker()
, or perhaps simply/* @vite-ignore */
for now if it has performance implications.Testing
Here's a stackblitz showing the current issue. Run
node index.js
in the terminal to execute the code.Related links
#221
The text was updated successfully, but these errors were encountered: