Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: PostCSS config #2455

Closed
marcobiedermann opened this issue Dec 10, 2017 · 13 comments
Closed

Feature: PostCSS config #2455

marcobiedermann opened this issue Dec 10, 2017 · 13 comments

Comments

@marcobiedermann
Copy link
Contributor

marcobiedermann commented Dec 10, 2017

Instead of hardcoding the postcss options into the default webpack config, I suggest moving this to a postcss.config.js file.
https://github.com/storybooks/storybook/blob/master/app/react/src/server/config/defaults/webpack.config.js#L21

This way it can be overwritten in your own project, similar to the babel.js config.
https://github.com/storybooks/storybook/blob/master/app/react/src/server/config/babel.js

https://github.com/storybooks/storybook/blob/585beccafdc4ea320d262b8d4db4b35b959007ef/app/react/src/server/babel_config.js

@igor-dv
Copy link
Member

igor-dv commented Dec 10, 2017

You can override the configuration with the full control mode: https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode

@marcobiedermann
Copy link
Contributor Author

@igor-dv I know but I think it is simpler to move the postcss configs into it's own file.

@danielduan
Copy link
Member

I think that most people are happy with the default settings. The extend and full control modes are for people like you who want to add or customize different webpack plugins.

There are many more people who require custom babel configs than postcss configs. We try to keep the code and setup complexity to a minimum. If there is demand for this feature, we'd be happy to add it.

@stale stale bot added the inactive label Jan 24, 2018
@stale stale bot closed this as completed Feb 8, 2018
@jpetitcolas
Copy link

I encountered the same issue, and I executed the following to use global postconfig.config.js file:

const path = require('path');

module.exports = (baseConfig, env, defaultConfig) => {
    defaultConfig.entry.styles = path.resolve(__dirname, '../src/styles/style.css');

    const cssRule = defaultConfig.module.rules.find(r => r.test.toString() === /\.css$/.toString());
    const postCssUse = cssRule.use.find(u => u.loader && u.loader.indexOf('postcss-loader') > -1);
    delete postCssUse.options;

    return defaultConfig;
};

I propose to check if we got a postcss.config.js file at root. If not, then we put the default current plugins function. If core team is OK with this change, I can give it a try in a PR. :)

@Hypnosphi Hypnosphi reopened this May 19, 2018
@stale stale bot removed the inactive label May 19, 2018
@Hypnosphi
Copy link
Member

@jpetitcolas Sounds good. We could also support it in storybook config directory

@stale stale bot added the inactive label Jun 9, 2018
@IanVS
Copy link
Member

IanVS commented Jul 6, 2018

Hi @jpetitcolas, do you still think you might make a PR? I think it would be really helpful for storybook to detect/use a postcss config file.

@stale stale bot removed the inactive label Jul 6, 2018
@stale stale bot added the inactive label Jul 30, 2018
@JordyPouw
Copy link

@jpetitcolas Thanks a lot! Good solution. Still works, should really be config for storybook :)

@stale stale bot removed the inactive label Aug 15, 2018
@storybookjs storybookjs deleted a comment from stale bot Oct 13, 2018
@storybookjs storybookjs deleted a comment from stale bot Oct 13, 2018
@storybookjs storybookjs deleted a comment from stale bot Oct 13, 2018
@storybookjs storybookjs deleted a comment from stale bot Oct 13, 2018
@ndelangen
Copy link
Member

So currently we still have this in our webpack.config.default.js:

            {
              loader: require.resolve('postcss-loader'),
              options: {
                ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
                postcss: {},
                plugins: () => [
                  require('postcss-flexbugs-fixes'), // eslint-disable-line
                  autoprefixer({
                    flexbox: 'no-2009',
                  }),
                ],
              },
            },

Does anyone want to open a PR fixing this issue?

Essentially we should check for the existence of the postcss.config.js file and if present, not set options, Right?

@ndelangen ndelangen added the todo label Oct 13, 2018
@kylemh
Copy link
Member

kylemh commented Oct 13, 2018

@ndelangen Im gonna get this.

Was thinking of copying this approach: https://github.com/zeit/next-plugins/blob/master/packages/next-css/css-loader-config.js

Are you okay with adding find-up as a dep?

@kylemh kylemh self-assigned this Oct 13, 2018
@ndelangen ndelangen added this to the next milestone Oct 13, 2018
@ndelangen
Copy link
Member

Yeah go for it 👍

@kylemh
Copy link
Member

kylemh commented Nov 22, 2018

Cool. So, I got postcss.config.js read from the official storybook example! Yay! 🎉

I'd like to discuss more with whoever has been working on presets and webpack configuration as I see a few problems...

The main issue is that postcss-loader exists as the first of many possible other loaders related to style loading, but never by itself. So, while the initial issue reads as: "Do this like you did with custom babel config" it feels as though it's not the same paradigm.

Example would be postcss-loader to sass-loader to css-loader to style-loader (from bottom to top in an array of loaders within module.rules)

Another issue would be that the default storybook config (as for as PostCSS config is concerned) is clearly conducive to React, but not vue-loader although it seems like @pksunkara is resolving that issue in a different manner. The specific example of React vs. Vue isn't the issue though, it's that I'm not aware of whether or not this default webpack config's style-loading rules even get utilized in some frameworks/examples (for example, in the Marko or Angular one).

If the default webpack config is not gonna be leveraged - and custom PostCSS rule loading will only be an aspect of React's preset - maybe we make this change there. If you'd like your postcss.config.js read outside of React, fallback to some of the original issue comments on this being a situation where one should break out into a custom webpack config otherwise.

@shilman shilman removed this from the next milestone Apr 26, 2019
@IanVS
Copy link
Member

IanVS commented Feb 2, 2021

I believe that this issue can be closed now that postcss.config.js files are detected and used.

@shilman
Copy link
Member

shilman commented Feb 17, 2021

Yup, closing this based on #13669

@shilman shilman closed this as completed Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants