Skip to content

postcss-bundler: conditional style exports support #1543

Closed as not planned
Closed as not planned
@pascalduez

Description

@pascalduez

What would you want to propose?

Greetings,

I'm currently trying to use postcss-bundler to import styles coming from a package declaring entry points and conditional exports: https://nodejs.org/api/packages.html#conditional-exports

The package exports:

"name": "@org/tokens",
"type": "module",
"main": "./dist/tokens.cjs",
"module": "./dist/tokens.js",
"style": "./dist/tokens.css",
"exports": {
  ".": {
    "import": "./dist/tokens.js",
    "require": "./dist/tokens.cjs",
    "types": "./dist/tokens.d.ts",
    "sass": "./dist/tokens.scss",
    "style": "./dist/tokens.css"
  },
},

The CSS file importing from the package:

@import url('node_modules:@org/tokens') layer(base);

Currently resulting in a CSSSyntaxError because it picks up the commonjs file ./dist/tokens.cjs.
I understand though that the style condition is not yet "standardized"?
Sass already honor the sass one though.

Suggested solution

Not exactly sure yet, will dive more into the code. Happy to get advises.
But given that postcss-bundler is aimed at CSS, supporting the style condition seems like a good addition.
Alternatively just add support for the style key at package.json root. (like postcss-import).

Additional context

Some references:

Validations

  • Follow our Code of Conduct
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Would you like to open a PR for this feature?

  • I'm willing to open a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions