Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-critical-css

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-critical-css

Generate critical CSS using PostCSS

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

PostCSS Critical CSS

This plugin allows you to define and output critical CSS using custom CSS properties.

Install

npm install postcss-critical-css --save-dev

Example

/* In foo.css */
.foo {
  critical-selector: this;
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

Will output:

/* In critical.css */
.foo {
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

Note that in the above example, the selector is rendered as it is written in the module. This may not be desireable, so you can alternatively identify the selector you'd like to use in your critical.css;

/* In foo.css */
.foo {
  critical-selector: .custom-selector;
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

Will output:

/* In critical.css */
.custom-selector {
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

If you'd like to ouptut the entire scope of a module, including children, you can!

/* in foo.css */
.foo {
  critical-selector: scope;
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

.foo a {
  color: blue;
  text-decoration: none;
}

Will output:

/* In critical.css */
.foo {
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

.foo a {
  color: blue;
  text-decoration: none;
}

And what if you need to output multiple critical CSS files (for example, if you have two different templates that do not share styles)? You can do that as well.

/* in foo.css */
.foo {
  critical-selector: this;
  critical-filename: secondary-critical.css;
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

Will output:

/* In secondary-critical.css */
.foo {
  border: 3px solid gray;
  display: flex;
  padding: 1em;
}

Options

outputPath Path to which critical CSS should be output Default: current working directory

preserve Whether or not to remove selectors from primary CSS document once they've been marked as critical. This should prevent duplication of selectors across critical and non-critical CSS. WARNING: this is a destructive option and may break styles relying on the cascade! Default: true

minify Minify output CSS Default: true

To Dos

  • Tests
  • More tests
  • More robust warnings

Keywords

FAQs

Package last updated on 09 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc