-
-
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
fix: call resolveId
hooks of custom plugins for css imports
#10555
base: main
Are you sure you want to change the base?
Conversation
Could you explain why we need to exclude internal plugins? If we are going to start having users plugins, should we directly the full pipeline and modify internal plugins where needed? If ours plugins don't work here, this may flag that users could also have issues with this change. |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
For reference, the fails in ecosystem-ci are the same as with main. |
It's an optimization. None of Vite's internal plugins expect to receive CSS imports, so there's no benefit to using them (apart from |
Ah, gotcha. I think it would be good to measure if having this optimization gets us much. But let's leave it as is until we discuss the PR in a team meeting. Added it to the board now. |
That's a fair point. Is there a recommended way to benchmark the test suite? Benchmarking isn't mentioned in the |
This comment was marked as spam.
This comment was marked as spam.
@aleclarson we discussed the PR in today's team meeting, and this sounds good. Before merging, we need to check that |
...plugins, | ||
aliasPlugin({ entries: resolved.resolve.alias }) |
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.
Shouldn't this be inverted? The alias plugin is the first one in the regular pipeline.
})) | ||
} else { | ||
container = | ||
resolverContainer || | ||
(resolverContainer = await createPluginContainer({ | ||
...resolved, | ||
plugins: [ | ||
...plugins, |
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.
Here it is tricky to properly order the plugins. The resolvePlugin should be injected in the same place where the regular resolve plugin is placed, no? Maybe the logic at 546 should generate two arrays, one for plugins before resolve, and one for the ones after it.
@aleclarson just a heads up in case you would like to push this feature for Vite 4, we're planning to release a beta soon and try to release the major around Dec 10. This is a feature we could include in a minor version later if not (just create the 4.1 milestone, we can move it there in that case) |
Hey folks is there a way we could get this in as a non-breaking change? For context I'm interested in this for our work on the Deno resolver plugin https://github.com/itsdouges/vite_plugin_deno_resolve This looks to be a great first party solution to getting the optimizer using our resolver. What work is missing to get this merged? |
We need patak's review to be resolved and tests for this. One way we could make this non-breaking is an experimental option to enable this feature, which could be a good workaround as the Vite plugin can turn it on internally. |
Hey @patak-dev would you have some time soon(TM) to review this? Thanks! |
@hakubo He has reviewed it, and he raised some issues with the current state of the PR. This PR needs someone with time to push it forward (eg: write tests and resolve Patak's concerns). |
@aleclarson right! Sorry missed that. I see it is added to milestone 5 for now. |
FWIW I was able to workaround it by implementing this trick on the plugin side. Given most plugins don't need to tap into |
I question whether |
I managed to do this originally using the following lines: export function createTsAliasPlugin(): PluginOption {
const tsResolvePlugin = tsconfigPaths({
root: monoRoot,
ignoreConfigErrors: true,
loose: true, // to support resolve alias in scss files(any other non-script files)
});
return [
tsResolvePlugin,
{
name: 'alias:style',
config() {
return {
resolve: {
alias: [
{
find: /(.*\.scss)$/,
replacement: '$1',
async customResolver(source, importer) {
if (importer && /\.scss/.test(importer)) {
// HACK: resolve alias in style files.
// @ts-ignore
return tsResolvePlugin.resolveId.apply(this, arguments);
}
},
},
],
},
};
},
},
];
} But after I saw your implementation, I try to use it as follows: export function createTsAliasPlugin(): PluginOption {
return [
tsResolvePlugin,
{
name: 'alias:style',
configResolved(config) {
patchCreateResolver(config, tsResolvePlugin);
},
},
];
} It should work fine as I see, but actually not. Do you guys know what happened deep within it? @aleclarson @bluwy |
Note: All plugins whose
name
matchesvite:*
are excluded from resolution of CSS imports. Any instances of@rollup/plugin-alias
are also excluded (useresolve.alias
instead).