postcss-load-config

npm node deps test coverage code style chat

Load Config

Install

npm i -D postcss-load-config

Usage

npm i -S|-D postcss-plugin

Install 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

Create a postcss section in your projects package.json

Project (Root)
  |– client
  |– public
  |
  |- package.json

.postcssrc

Create a .postcssrc file in JSON or YAML format

ℹ️ It's recommended to use an extension (e.g .postcssrc.json or .postcssrc.yml) instead of .postcssrc

.postcssrc.json

.postcssrc.yml

.postcssrc.js or postcss.config.js

You 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 to require() each plugin

Options

Name
Type
Default
Description

{String}

undefined

Destination File Path

{String|Object}

false

Enable/Disable Source Maps

{String}

undefined

Source File Path

{String|Function}

false

Custom PostCSS Parser

{String|Function}

false

Custom PostCSS Syntax

{String|Function}

false

Custom PostCSS Stringifier

parser

.postcssrc.js

syntax

.postcssrc.js

stringifier

.postcssrc.js

.postcssrc.js

⚠️ In most cases options.from && options.to are set by the third-party which integrates this package (CLI, gulp, webpack). It's unlikely one needs to set/use options.from && options.to within a config file. Unless you're a third-party plugin author using this module and its Node API directly dont't set options.from && options.to yourself

to

from

Plugins

{} || null

The plugin will be loaded with defaults

.postcssrc.js

⚠️ {} must be an empty {Object} literal

{Object}

The plugin will be loaded with given options

.postcssrc.js

false

The plugin will not be loaded

.postcssrc.js

Ordering

Plugin 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.g postcss-loader). Check the specific module's README for more information about what is available on the respective ctx

Examples

postcss.config.js

webpack.config.js

Maintainers

Contributors

Last updated

Was this helpful?