Skip to content

feat: call resolveId hooks for CSS urls#3032

Closed
aleclarson wants to merge 1 commit into
vitejs:mainfrom
aleclarson:feat/css-resolveId
Closed

feat: call resolveId hooks for CSS urls#3032
aleclarson wants to merge 1 commit into
vitejs:mainfrom
aleclarson:feat/css-resolveId

Conversation

@aleclarson
Copy link
Copy Markdown
Contributor

Description

Allow for references to virtual modules in CSS url(...) expressions.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@patak-cat
Copy link
Copy Markdown
Member

For reference, this PR has been discussed and approved in a team meeting. We need test cases to be able to merge. If someone wants to see this in, consider doing a PR to this branch with a test case, or sending a new PR starting from it to main

@jonathantneal
Copy link
Copy Markdown

Hey @aleclarson, I’m learning about Vite and wondering if you could help me understand the difference between resolveUrl and this.resolve. While I did not find much documentation for resolveUrl or the createResolver method that generates it, I did see that it looked a lot like what this.resolve performs.

  • What is the difference between resolveUrl and this.resolve?
  • Is there functionality they both do which may be duplicated with this change?
  • Is there functionality they each do that the other does not?

@aleclarson
Copy link
Copy Markdown
Contributor Author

aleclarson commented Feb 24, 2022

Hi @jonathantneal

The resolveUrl function is created here:

const resolveUrl = config.createResolver({
preferRelative: true,
tryIndex: false,
extensions: []
})

It uses config.createResolver, which only uses @rollup/plugin-alias and (optinally) vite:resolve internal plugin .

(aliasContainer = await createPluginContainer({
...resolved,
plugins: [aliasPlugin({ entries: resolved.resolve.alias })]
}))

(resolverContainer = await createPluginContainer({
...resolved,
plugins: [
aliasPlugin({ entries: resolved.resolve.alias }),
resolvePlugin({
...resolved.resolve,
root: resolvedRoot,
isProduction,
isBuild: command === 'build',
asSrc: true,
preferRelative: false,
tryIndex: true,
...options
})

@jonathantneal
Copy link
Copy Markdown

Thanks, @aleclarson. Does this.resolve also use @rollup/plugin-alias and (optionally) vite:resolve? reference

I was curious how they differed and also learning why they differed.

@aleclarson
Copy link
Copy Markdown
Contributor Author

I'm not clear on why config.createResolver doesn't use all plugins. I think it was originally designed for use by Vite's dependency optimizer, then used for CSS url resolution post hoc (for unknown reasons).

Does this.resolve also use @rollup/plugin-alias and (optionally) vite:resolve?

This is true, and a good point. We can probably remove the resolveUrl function altogether here, but some tests to confirm that are needed (which I don't have time to contribute).

@bluwy
Copy link
Copy Markdown
Member

bluwy commented Dec 29, 2022

Superseded by #10555

@bluwy bluwy closed this Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: css needs test p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants