ITADN

Polyfill API for importFrom files?

#1788Closedhgl 创建于 2026-02-26
feature request
H
hglcommented
### What would you want to propose? I'm trying to use the `matchMedia` DOM API, and I would like the source of truth to be something like ```js // data.js export default { customMedia: { '--wide': '(width >= 600px)' } } ``` So I can import this file and use the actual value, since there is currently no native support for custom media for most browsers. However, I'd like `matchMedia` to get the value of `(min-width: 600px)` instead of the fancy range value. ### Suggested solution I wonder if it makes sense to offer a polyfill API where you can do something like this ```js // data.js import { polyfillCustomMedia } from "postcss-custom-media" // or import { polyfillCustomMedia } from "postcss-preset-env" export default { customMedia: polyfillCustomMedia({ '--wide': '(width >= 600px)' }) } ``` Where the value optionally gets converted to the following depending on the browserlist value: ```js export default { customMedia: { '--wide': '(min-width: 600px)' } } ``` So that I can use the value that has a wider support in js. ### Additional context _No response_ ### Validations - [x] Follow our [Code of Conduct](https://github.com/csstools/postcss-plugins/blob/master/CODE_OF_CONDUCT.md) - [x] 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? - [x] I'm willing to open a PR
关闭于 2026-02-26 1 条评论