@greenwood/plugin-postcss
v0.30.2
Published
A Greenwood plugin for loading PostCSS configuration and applying it to your CSS.
Downloads
580
Maintainers
Readme
@greenwood/plugin-postcss
Overview
A Greenwood plugin for loading PostCSS configuration and applying it to your CSS. For more information and complete docs on Greenwood, please visit our website.
This package assumes you already have
@greenwood/cli
installed.
Installation
You can use your favorite JavaScript package manager to install this package.
# npm
$ npm i -D @greenwood/plugin-postcss
# yarn
$ yarn add @greenwood/plugin-postcss --dev
# pnpm
$ pnpm add -D @greenwood/plugin-postcss
Usage
Add this plugin to your greenwood.config.js:
import { greenwoodPluginPostCss } from '@greenwood/plugin-postcss';
export default {
// ...
plugins: [
greenwoodPluginPostCss()
]
}
By default, this plugin provides a default postcss.config.js that includes support for postcss-preset-env using browserslist and postcss-import.
export default {
plugins: [
(await import('postcss-import')).default,
(await import('postcss-preset-env')).default
]
};
Note: Greenwood provides the behavior of postcss-import out of the box.
Options
Configuration
To use your own PostCSS configuration, you'll need to create two (2) config files in the root of your project, by which you can provide your own custom plugins / settings that you've installed.
- postcss.config.js
- postcss.config.mjs
Example:
// postcss.config.js
module.exports = {
plugins: [
require('postcss-nested')
]
};
// postcss.config.mjs
export default {
plugins: [
(await import('postcss-nested')).default
]
};
Eventually once PostCSS adds support for ESM configuration files, then this will drop to only needing one file.
Extend Config
If you would like to extend the default configuration with your own custom postcss.config.js, you can enable the extendConfig
option of this plugin
import { greenwoodPluginPostCss } from '@greenwood/plugin-postcss';
export default {
// ...
plugins: [
greenwoodPluginPostCss({
extendConfig: true
})
]
};
This will then process your CSS with PostCSS using the configured plugins / settings you provide, merged after the default Greenwood configuration listed above.