postcss / postcss-cli

CLI for postcss
Other
836 stars 93 forks source link

in monorepo, cli fail to set postconfig custom directory to look for a config file #331

Closed huchangfa123 closed 4 years ago

huchangfa123 commented 4 years ago

question

I created a monorepo project and i want to set all package with the same postcss.config , the catalog of project as follow: 企业微信截图_63c57975-9b67-4dab-bcd0-a2730a8433b7

so , i put a postcss.config in root directory. And in each package package.json , i set the cli command as follow: 企业微信截图_2464cd77-87a4-4329-ae76-51ca629c58e6

but it's not work. After testing, i find "--config" as if can only set the directory in below directory , but not upward.

babel can set the config directory use "--root-mode upward" to find the config file in upward directory, I wish this cli can provide the same command to work , or improve the command "--config" to fixed my question

thanks.

RyanZim commented 4 years ago

postcss-cli should be able to find your config without the --config option. It checks parent directories up to your user home directory by default. Let me know if that doesn't work.

huchangfa123 commented 4 years ago

this project is monorepo project.And the postcss config file is in root path. In posscss config , I use mixin plugin . And set a mixin item as follow: image

pageTitle packjson as follow: 企业微信截图_3faa0a72-fc0e-4e0e-ad28-d4f90f14a48a

the root packjson as follow: 企业微信截图_8f728b3a-797b-47bd-a321-acf79502573a use lerna to build all pakages

if the postcss config is in root path. when I use mixin in pageTitle.css and build , it's building wrong as follow: image

only put the config file into to the same path, building is success image image

but if do this, each package in packages have to add the same config file of postcss. Babel can use "--root-mode upward" to make all pakage use the same config file in root path. So, I wish postcss can do this too. And I tried to use "--config", but failed. Are there any config can finish this ?

thanks a lot.

RyanZim commented 4 years ago

postcss-cli is picking up your config alright. If it wasn't, it would error out with a different error. The problem isn't that it's not reading your config, the problem is that postcss-mixins can't find where your mixin is defined. I'm not super familiar with postcss-mixins, are you passing any options to it? Also, you showed the CSS where you defined your mixin, where is that located? styles/mixins/style.css?

huchangfa123 commented 4 years ago

yes, you're right. In postcss.config: image the relative directory of mixin css should change to '../../styles/mixins', the building will success. the directory is not relatived with the root path where postcss.config stay, but relatived with the path of pageTitle's package.json.

RyanZim commented 4 years ago

It's actually probably relative to the directory that the CLI command is run from, which in your case would be the pageTitle directory. If you want to make it absolute, you could set it to path.join(__dirname, 'styles/mixins'); that will make it work the same no matter where the command is run.