postcss-plugins icon indicating copy to clipboard operation
postcss-plugins copied to clipboard

[QUESTION] Plugin: PostCSS Design Tokens

Open fredboyle opened this issue 3 years ago • 3 comments
trafficstars

Is there a recommended PostCSS plugin or method to allow the use of node_module paths in the @design-tokens rule?

Example:

@design-tokens url('@org/module-name/dist/json/tokens.json') format('style-dictionary3');

fredboyle avatar Aug 24 '22 18:08 fredboyle

The only way to currently do this is to write out the full path to your node_modules folder.

An example of this can be found in this test :

https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-design-tokens/test/imported.css

romainmenke avatar Aug 24 '22 19:08 romainmenke

Ugh that's a bummer. Thanks.

fredboyle avatar Aug 24 '22 20:08 fredboyle

I am going to leave this open for a bit because I would like to explore what the options are.

Maybe we can improve things :)

romainmenke avatar Aug 24 '22 21:08 romainmenke

@fredboyle We might be able to get this to work with this format :

@design-tokens url('node_modules://@org/module-name/dist/json/tokens.json') format('style-dictionary3');

The node_modules:// scheme is used to differentiate this import from a regular file path. It indicates that the plugin should use node's require.resolve to traverse node_modules directories in search for the listed package.

I considered npm:// but that is misleading because the files are not loaded from npm directly.

Would this solve your issue?

romainmenke avatar Aug 28 '22 13:08 romainmenke

@romainmenke Seems reasonable to me and not much of a burden on developers. Makes things a bit more universal and without the need to calculate relative paths every time.

fredboyle avatar Aug 29 '22 18:08 fredboyle

@fredboyle We have released v1.2.0 which should resolve this : https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-design-tokens/CHANGELOG.md#120-september-7-2022

Can you test this version to make sure it works as expected?

If you happen to use the VSCode extension, that one has also been updated with support for node_modules paths.

romainmenke avatar Sep 07 '22 07:09 romainmenke

Closing because I assume this now works correct. If you do encounter any more issues feel free to open a new issue or to post a comment here.

Thank you again using the packages and for giving feedback!

romainmenke avatar Sep 15 '22 06:09 romainmenke