Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

postcss-autoreset

maximkoretskiy4.2kMIT3.1.0

PostCSS plugin for partial styles reset

postcss, postcss-plugin, css, reset, autoreset, isolation

readme

PostCSS Auto Reset

Build Status NPM David DM

PostCSS plugin for automatic conditional rules reset. Useful for creation of bullet-proof styles isolation in your extension. Can be used in combination with postcss-initial.

The following CSS is written in BEM notation.

.block {
  padding: 1em;
}

.block:hover {
  background-color: red;
}

.block__element {
  margin: 1em;
}

.block--modifier {
  border: 1em;
}
.block,
.block__element {
  /* combined reset block */
  all: initial;
}

.block {
  /* reseted */
  padding: 1em;
}

.block:hover {
  /* ignored, we don`t need to reset pseudoclasses  */
  background-color: red;
}

.block__element {
  /* reseted */
  margin: 1em;
}

.block--modifier {
  /* ignored, we don`t need to reset BEM modifiers  */
  border: 1em;
}

Options

reset

Set of properties that we use to reset rules.
Takes string or object.
Possible values:

  • 'initial' - all: initial;
  • 'sizes' - reset size properties.

Use object to create your own reset. CSS-in-JS notation is supported.

Example

postcss([
  require("postcss-autoreset")({
    reset: {
      margin: 0,
      padding: 0,
      borderRadius: 0,
    },
  }),
]);

rulesMatcher

Rules filter function.
Takes string or function.
Possible values:

  • 'bem' - reset all BEM blocks and element, ignore modifiers and pseudoclasses. (naming: .block__element-modifier);
  • 'suit' - reset all SUIT CSS components and parts, ignore modifiers, states and pseudoclasses.

You can define custom rules filter to fit your styles naming.

Example

postcss([
  require("postcss-autoreset")({
    rulesMatcher: (rule) => rule.selector.match(/regexp/),
  }),
]);

Reset only simple rules. See #28

postcss([
  require("postcss-autoreset")({
    rulesMatcher: (rule) => rule.selector.match(/^[.]\w+$/),
  }),
]);

Usage

Step 1: Install plugin:

npm install --save-dev postcss postcss-autoreset

Step 2: Check you project for existed PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-autoreset')(),
    require('autoprefixer')
  ]
}

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

[Unreleased]

[3.1.0] - 2024-02-19

  • update postcss-js and some dependencies

[3.0.4] - 2020-05-21

  • Move the selector matcher to OnceExit

[3.0.0] - 2020-09-29

  • Update to PostCSS v8

[2.0.2] - 2018-02-25

  • Add support for prefixed keyframes(#27, #25). Thnx @olavhaugen for PR

[2.0.1] - 2017-08-25

  • Fix keyframes adding to common reset list .Thnx @copycut for suggestion!

[2.0.0] - 2017-07-30

  • Update to PostCSS 6

[1.2.1] - 2016-10-09

Thnx to @giuseppeg and simonsmith for contribution!

  • Do not modify css if not required
  • Fix duplicate selector issue when using nested rulesets. (#18)

[1.2.0] - 2016-09-29

[1.1.5] - 2016-01-21

  • Fix plugin prepublish script again with babel-plugin-add-module-exports. Thnx @mikaa123 for patience %)
  • Add integration test to prevent this bug.

[1.1.4] - 2016-01-21

  • Fix plugin prepublish script with babel-plugin-transform-es2015-modules-umd. Thnx @mikaa123 for bugreport

[1.1.3] - 2016-01-21

  • Put all resets in one rule. Thnx @DanGamble89 for idea
  • Add virtual source for generated code. Thnx @ai for review
  • Change test suite from tape to ava
  • Change test suite from ava to mocha(for more helpfull diffs)
  • Update deps

[1.1.2] - 2016-01-10

  • Fixed default matchers pseudoclasses matching. Thnx to @kinday for contribution.

[1.1.1] - 2015-12-16

  • Roll back dependencies update to fix test suite work

[1.1.0] - 2015-12-16

  • Added css2js custom rules notation support. Thnx to @ai for idea
  • Update deps

[1.0.0] - 2015-08-29

First project release. Added

  • BEM and Suit support
  • README docs