-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
feat: add list of known js source extensions to config #3828
base: main
Are you sure you want to change the base?
Conversation
if (!config.knownJsSrcExtensions) { | ||
config.knownJsSrcExtensions = [...DEFAULT_KNOWN_JS_SRC_EXTENSIONS] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can wait until we discuss this with Evan, but I think it is better if this works like assetsInclude
. So the user will give us extra extensions and they are added to the ones supported by default by vite.
@@ -416,6 +447,7 @@ export async function resolveConfig( | |||
assetsInclude(file: string) { | |||
return DEFAULT_ASSETS_RE.test(file) || assetsFilter(file) | |||
}, | |||
knownJsSrcExtensions: resolvedKnownJsSrcExtensions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed a bit about this in Discord. IMO we could also use the same scheme utilized by assetsInclude
here. In the ResolvedConfig, we will have a resolved.isJsRequest(path)
function that plugins can then use. This is something else to discuss with Evan, if we go here, we may want to have all these helpers in resolve.utils.isJsRequest
, but I am not sure if it is really needed and the flat structure is enough here. @antfu what do you think?
Commenting for reference, as this was already discussed in Discord. We may be able to avoid the need for defining these known imports altogether, so for the moment is better to hold on with exposing a new config option here. We can continue to accept new known types if that helps the ecosystem in the meanwhile. @dominikg I'll make this one a draft for the time being. |
@patak-dev do you happen to remember how it was that we might be able to avoid defining these known imports? Is there any update on that or whether we should move forward with this PR? I see you referred to this PR positively in a recent comment, so I'm wondering if there might be a path forward for it if it were rebased? |
Hello! I am finding hard to make vite to pre-process |
I believe in the last meeting we had decided to close this in favour of #9981. We don't completely remove |
not sure i like the way plugins have to use configureServer to set that header manually, thats a lot of repeated code for a common need. most frameworks building on vite have a custom extension for their files so we should provide a better util than #9981 (comment) for them to set this up |
Isn't |
browsers are never going to set that header themselves if they see an import to |
so they add it based on the fact that the url was given to it either in the src value of a script tag or imported from such a script? |
Yes browsers will add that information. The spec doesn't mention requiring to add that information, but if browsers already did, I don't see them not doing it anymore without breaking the web. For non-browsers when we drop |
i believe that would be an unneccessary regression, an internal Also is this purely a dev concern or something that also needs to be available at buildtime? |
It's dev only. I personally don't think it'll be a big regression in practice, unless you're fetching the resource directly from curl or testing, but those things aren't common for most users who develop on Vite-based projects. We could discuss this in the next meeting again, but either ways I don't think this discussion is blocking from merging the other PR as it has other benefits too. |
Description
implementation of #3219 with config option at runtime as requested in #3219 (comment)
Separate PR to be able to compare the two and avoid having to rebase/force-push
I don't really like how the array is passed through several function calls to reach the util, but without some structural changes this is the least invasive i could manage.
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).