@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/cliinstalled.
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.
Types
Types should automatically be inferred through this package's exports map, but can be referenced explicitly in both JavaScript (JSDocs) and TypeScript files if needed.
/** @type {import('@greenwood/plugin-postcss').PostCssPlugin} */
import type { PostCssPlugin } from '@greenwood/plugin-postcss';
Options
Configuration
To use your own PostCSS configuration, you'll want to create your own postcss.config.js (or .ts) file at the root of your project, by which you can provide your own custom plugins and settings.
export default {
plugins: [
(await import('postcss-nested')).default
]
};
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.