feature request: support conditional exports (package.json `exports` field)

Open
#492 11 comments 21 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript
Domain
frontend, tooling

Research direction

Start by tracing how postcss-import resolves package imports and the existing style field, then compare that behavior with the conditional exports examples in the issue. Add support for the requested exports paths with exports taking precedence over style, and verify both package styles and conditional exports remain legible to postcss-import.

Written by the indexing model from the issue text.

Description

discussion enhancement

Love the style support, but would really helpful for conditional exports to also be legible to postcss-import:

{
  ...,
  "exports": {
    ".": "./dist/index.js",
    "./*": "./dist/lib/*/index.js",
    "./styles": "./dist/styles/index.css",
    "./styles/*": "./dist/styles/*/index.css",
    "./package.json": "./package.json"
  },
  ...,
}

The main reason I suggest this is because I cannot specify an @import "my-package/styles" statement in a way that is supported by both esbuild (supports standardized package.json exports, but not nonstandard style) and postcss-import (where situation is reversed). my-package/styles is the only thing that works for esbuild, but my-package is the only thing that works for postcss-import.

I would recommend following the Node doctrine of "if exports exists, it overrides anything else" (i.e. style field). Also thank you for maintaining this project, it is a core part of modern development workflows IMO, only reason I suggest the enhancement.

Dominant language
JavaScript
Stars
1.4k
Forks
117
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from postcss/postcss-import

All issues in postcss/postcss-import

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.