postcss-load-config
Load Config
Install
npm i -D postcss-load-configUsage
npm i -S|-D postcss-pluginInstall all required postcss plugins and save them to your package.json dependencies/devDependencies
Then create a postcss config file by choosing one of the following formats
package.json
package.jsonCreate a postcss section in your projects package.json
Project (Root)
|– client
|– public
|
|- package.json.postcssrc
.postcssrcCreate a .postcssrc file in JSON or YAML format
ℹ️ It's recommended to use an extension (e.g
.postcssrc.jsonor.postcssrc.yml) instead of.postcssrc
.postcssrc.json
.postcssrc.yml
.postcssrc.js or postcss.config.js
.postcssrc.js or postcss.config.jsYou may need some logic within your config. In this case create JS file named .postcssrc.js or postcss.config.js
You can export the config as an {Object}
.postcssrc.js
Or export a {Function} that returns the config (more about the ctx param below)
.postcssrc.js
Plugins can be loaded either using an {Object} or an {Array}
{Object}
.postcssrc.js
{Array}
.postcssrc.js
⚠️ When using an
{Array}, make sure torequire()each plugin
Options
parser
parser.postcssrc.js
syntax
syntax.postcssrc.js
stringifier
stringifier.postcssrc.js
.postcssrc.js
⚠️ In most cases
options.from&&options.toare set by the third-party which integrates this package (CLI, gulp, webpack). It's unlikely one needs to set/useoptions.from&&options.towithin a config file. Unless you're a third-party plugin author using this module and its Node API directly dont't setoptions.from&&options.toyourself
to
tofrom
fromPlugins
{} || null
{} || nullThe plugin will be loaded with defaults
.postcssrc.js
⚠️
{}must be an empty{Object}literal
{Object}
{Object}The plugin will be loaded with given options
.postcssrc.js
false
falseThe plugin will not be loaded
.postcssrc.js
Ordering
OrderingPlugin execution order is determined by declaration in the plugins section (top-down)
Context
When using a {Function} (postcss.config.js or .postcssrc.js), it's possible to pass context to postcss-load-config, which will be evaluated while loading your config. By default ctx.env (process.env.NODE_ENV) and ctx.cwd (process.cwd()) are available on the ctx {Object}
ℹ️ Most third-party integrations add additional properties to the
ctx(e.gpostcss-loader). Check the specific module's README for more information about what is available on the respectivectx
Examples
postcss.config.js
webpack.config.js
Maintainers
Contributors
Last updated
Was this helpful?




