Skip to content

Commit 57dac24

Browse files
vinklaegoist
authored andcommitted
Allow boolean plugins support (#142)
Allow boolean plugins similar to how Rollup plugins work. In the Rollup plugins array you may write the following to only run a plugin for production usage: ```js plugins: [ (process.env.NODE_ENV === 'production' && terser()) ] ``` This pull request allow the same approach for PostCSS plugins: ```js plugins: [ (process.env.NODE_ENV === 'production' && cssnano()) ] ``` [Example of how Rollup has implemented this feature.](https://github.com/rollup/rollup/blob/f58d1e60a3da4b8470e5d56aa0caef2ecadec2b8/src/rollup/index.ts#L107)
1 parent b201582 commit 57dac24

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function inferOption(option, defaultValue) {
1616

1717
export default (options = {}) => {
1818
const filter = createFilter(options.include, options.exclude)
19+
const postcssPlugins = Array.isArray(options.plugins) ? options.plugins.filter(Boolean) : options.plugins
1920
const sourceMap = options.sourceMap
2021
const postcssLoaderOptions = {
2122
/** Inject CSS as `<style>` to `<head>` */
@@ -34,7 +35,7 @@ export default (options = {}) => {
3435
/** PostCSS options */
3536
postcss: {
3637
parser: options.parser,
37-
plugins: options.plugins,
38+
plugins: postcssPlugins,
3839
syntax: options.syntax,
3940
stringifier: options.stringifier,
4041
exec: options.exec

0 commit comments

Comments
 (0)