Skip to content
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

Support lightningcss "resolver" option #16593

Open
4 tasks done
olivierbossel opened this issue May 3, 2024 · 3 comments
Open
4 tasks done

Support lightningcss "resolver" option #16593

olivierbossel opened this issue May 3, 2024 · 3 comments

Comments

@olivierbossel
Copy link

Description

Hi their!
Hope you are doing well! At start, thanks for your work!

It will be nice to be able to specify the resolver options supported by the lightningcss compiler but that seems to be not passed and supported on the vite side...

export type LightningCSSOptions = {

Suggested solution

Add the resolver option in the LightningCSSOptions type as well as passing it to the lightningcss compiler.

Alternative

No response

Additional context

Example of use:

// vite.config.ts
import { browserslistToTargets } from "lightningcss";
import fs from 'fs';
import path from 'path';

export default {
  css: {
    transformer: "lightningcss",
    lightningcss: {
      resolver: {
        read(filePath) {
          console.log(filePath);
          return fs.readFileSync(filePath, "utf8");
        },
        resolve(specifier, from) {
          return path.resolve(path.dirname(from), specifier);
        },
      },
      targets: browserslistToTargets(browserslist(">= 0.25%")),
    },
  },
  build: {
    cssMinify: "lightningcss",
  },
};

Validations

@bluwy
Copy link
Member

bluwy commented May 13, 2024

What is the usecase for accepting a resolver option? Vite has its own internal resolver too and it should use that. Similar to how postcss-import and CSS preprocessors like SCSS, Stylus, all use Vite's resolver only.

@olivierbossel
Copy link
Author

olivierbossel commented May 13, 2024

The idea is to allow use of globs into the css @import like so:

@import './components/**/*.css';

For now it's not working at all.
I checked with the lightningcss repo contributors parcel-bundler/lightningcss#735 but they think it's on the vite side.

If I check the postcss-import-ext-glob plugin https://github.com/dimitrinicolas/postcss-import-ext-glob/blob/master/index.js, it's inside the postcss AST that the support is added.

My guess is that the simpliest way to allow devs to support custom imports inside the lighningcss module is to pass the resolver options down to lighntningcss from the lighningcss options object like in my example above.

Unless you have another idea that I will be happy to implement and share :)

@bluwy
Copy link
Member

bluwy commented May 14, 2024

In that case, it seems like a bug (or technically a feature request) to me to make import globs work with lightningcss. There's also a corresponding postcss feature request: #12336. If we can get this working, then I don't think we have to expose the resolver option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants