{"id":20348858,"url":"https://github.com/zgreen/postcss-critical-css","last_synced_at":"2025-05-06T23:45:51.201Z","repository":{"id":48034696,"uuid":"52451845","full_name":"zgreen/postcss-critical-css","owner":"zgreen","description":"PostCSS plugin to define and output critical CSS using custom atRules, and/or custom CSS properties. Critical CSS may be output to one or more files, as defined within the plugin options or within the CSS.","archived":false,"fork":false,"pushed_at":"2022-04-09T02:11:09.000Z","size":1205,"stargazers_count":88,"open_issues_count":16,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T00:48:09.571Z","etag":null,"topics":["critical-css","css","postcss","postcss-critical-css","postcss-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zgreen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-24T15:17:58.000Z","updated_at":"2025-03-04T12:14:17.000Z","dependencies_parsed_at":"2022-09-17T11:13:17.909Z","dependency_job_id":null,"html_url":"https://github.com/zgreen/postcss-critical-css","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgreen%2Fpostcss-critical-css","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgreen%2Fpostcss-critical-css/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgreen%2Fpostcss-critical-css/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgreen%2Fpostcss-critical-css/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zgreen","download_url":"https://codeload.github.com/zgreen/postcss-critical-css/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788404,"owners_count":21804280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["critical-css","css","postcss","postcss-critical-css","postcss-plugin"],"created_at":"2024-11-14T22:22:45.028Z","updated_at":"2025-05-06T23:45:51.185Z","avatar_url":"https://github.com/zgreen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostCSS Critical CSS\n\nThis plugin allows the user to define and output critical CSS using custom atRules, and/or custom CSS properties. Critical CSS may be output to one or more files, as defined within the [plugin options](#plugin-options) and/or within the CSS. Depending on the plugin options used, processed CSS may be left unchanged, or critical CSS may be removed from it.\n\n## Install\n\n`npm install postcss-critical-css --save`\n\n## Examples\n\nAn example is available in this repo. See the `/example` directory, and use the command `npm run example` to test it out.\n\n## Usage examples\n\nAll examples given below show the input CSS and the critical CSS that is output from it. Note that the input CSS will remain unchanged, unless `preserve` is set to `false` in the [plugin options](#plugin-options). Use `npm run example` to see how this works.\n\n### Using the `@critical` atRule\n\n```css\n/* In foo.css */\n@critical;\n\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\nWill output:\n\n```css\n/* In critical.css */\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\n### Using the `@critical` atRule with a custom file path\n\n```css\n/* In foo.css */\n@critical bar.css;\n\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\nWill output:\n\n```css\n/* In bar.css */\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\n### Using the `@critical` atRule with a subset of styles\n\n```css\n/* In foo.css */\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n\n@critical {\n  .bar {\n    border: 10px solid gold;\n    color: gold;\n  }\n}\n```\n\nWill output:\n\n```css\n/* In critical.css */\n.bar {\n  border: 10px solid gold;\n  color: gold;\n}\n```\n\n### Using the custom property, `critical-selector`\n\n```css\n/* In foo.css */\n.foo {\n  critical-selector: this;\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\nWill output:\n\n```css\n/* In critical.css */\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\n### Using the custom property, `critical-selector`, with a custom selector.\n\n```css\n/* In foo.css */\n.foo {\n  critical-selector: .bar;\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\nWill output:\n\n```css\n/* In critical.css */\n.bar {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\n### Using the custom property, `critical-filename`\n\n```css\n/* in foo.css */\n.foo {\n  critical-selector: this;\n  critical-filename: secondary-critical.css;\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\nWill output:\n\n```css\n/* In secondary-critical.css */\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n```\n\n### Using the custom property, `critical-selector`, with value `scope`\n\nThis allows the user to output the entire scope of a module, including children.\n\n```css\n/* in foo.css */\n.foo {\n  critical-selector: scope;\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n\n.foo a {\n  color: blue;\n  text-decoration: none;\n}\n```\n\nWill output:\n\n```css\n/* In critical.css */\n.foo {\n  border: 3px solid gray;\n  display: flex;\n  padding: 1em;\n}\n\n.foo a {\n  color: blue;\n  text-decoration: none;\n}\n```\n\n## Plugin options\n\nThe plugin takes a single object as its only parameter. The following properties are valid:\n\n| Arg          | Type      | Description                                                                                                                                                                           | Default                   |\n| ------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |\n| `outputPath` | `string`  | Path to which critical CSS should be output                                                                                                                                           | Current working directory |\n| `outputDest` | `string`  | Default critical CSS file name                                                                                                                                                        | `\"critical.css\"`          |\n| `preserve`   | `boolean` | 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. | `true`                    |\n| `minify`     | `boolean` | Minify output CSS?                                                                                                                                                                    | `true`                    |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzgreen%2Fpostcss-critical-css","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzgreen%2Fpostcss-critical-css","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzgreen%2Fpostcss-critical-css/lists"}