Skip to content

Handle node's subpath imports (#...) in CSS url('...')s #23261

Description

@dummdidumm

Description

Node's subpath imports syntax exists for a long time now, allowing you to declare aliases to files inside your code base:

{
  "imports": {
     "#lib/*": "./src/lib/*"
  }
}

Sadly, Vite does not handle these inside url('...') statements inside CSS.

Suggested solution

When coming across a url('...') in CSS, and it starts with a hash, check the project's package.json to see if this matches an entry in the imports map and resolves to a file in the project.

This is already done for defined aliases so it would only make sense to apply it to Node imports, too.

Alternative

Keep using relative imports or aliases, both of which are not as nice.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions