PostCSS Preset Env lets you convert modern CSS into something most browsers can understand, determining the polyfills you need based on your targeted browsers or runtime environments.
The stage option determines which CSS features to polyfill, based upon their stability in the process of becoming implemented web standards.
postcssPresetEnv({ stage:0 })
The stage can be 0 (experimental) through 4 (stable), or false. Setting stage to false will disable every polyfill. Doing this would only be useful if you intended to exclusively use the features option.
Without any configuration options, PostCSS Preset Env enables Stage 2 features.
features
The features option enables or disables specific polyfills by ID. Passing true to a specific feature ID will enable its polyfill, while passing false will disable it.
postcssPresetEnv({/* use stage 3 features + css nesting rules */ stage:3, features: {'nesting-rules':true }})
Passing an object to a specific feature ID will both enable and configure it.
postcssPresetEnv({/* use stage 3 features + css color-mod (warning on unresolved) */ stage:3, features: {'color-mod-function': { unresolved:'warn' } }})
Any polyfills not explicitly enabled or disabled through features are determined by the stage option.
browsers
The browsers option determines which polyfills are required based upon the browsers you are supporting.
PostCSS Preset Env supports any standard browserslist configuration, which can be a .browserslistrc file, a browserslist key in package.json, or browserslist environment variables.
The browsers option should only be used when a standard browserslist configuration is not available.
The insertBefore and insertAfter keys allow you to insert other PostCSS plugins into the chain. This is only useful if you are also using sugary PostCSS plugins that must execute before or after certain polyfills. Both insertBefore and insertAfter support chaining one or multiple plugins.
The preserve option determines whether all plugins should receive a preserve option, which may preserve or remove otherwise-polyfilled CSS. By default, this option is not configured.
postcssPresetEnv({ preserve:false// instruct all plugins to omit pre-polyfilled CSS});
importFrom
The importFrom option specifies sources where variables like Custom Media, Custom Properties, Custom Selectors, and Environment Variables can be imported from, which might be CSS, JS, and JSON files, functions, and directly passed objects.
Multiple sources can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, functions, and objects will use different namespaces to import different kinds of variables.
The exportTo option specifies destinations where variables like Custom Media, Custom Properties, Custom Selectors, and Environment Variables can be exported to, which might be CSS, JS, and JSON files, functions, and directly passed objects.
Multiple destinations can be passed into this option as well, and they will be parsed in the order they are received. JavaScript files, JSON files, and objects will use different namespaces to import different kinds of variables.