HenrikJoreteg / hjs-webpack

Helpers/presets for setting up webpack with hotloading react and ES6(2015) using Babel.
1.79k stars 129 forks source link

PostCSS config file is not honored if present #326

Closed wkillerud closed 7 years ago

wkillerud commented 7 years ago

Explanation of the issue

hjs-webpack does not honor the plugins option in postcss.config.js if present. This because the postcss-loader is always given an options object with at least an empty array.

With the new Webpack 2 config syntax adding plugins or tweaking options involves an ugly hack to delete the options object so the loader looks for the config file:

const config = getConfig({
    ...
});

config.module.rules.forEach(rule => {
    rule.use.forEach(use => {
        if (use.loader === 'postcss-loader') {
            delete use.options;
        }
    });
});

module.exports = config;

What are the consequences?

The plugins and their options defined in postcss.config.js are ignored.

To see the problem in effect, run npm run webpack, then npm run webpack:postcss and see the differences in output in dist/main.css.

Proposed solution

Have hjs-webpack look for the presence of postcss.config.js and merge its contents with whatever hjs-webpack is configured with, and have postcss.config.js override any options that are defined in both places.

wkillerud commented 7 years ago

A minimal project demoing the issue: https://github.com/wkillerud/hjs-postcss-config