1.1.1 • Published 6 years ago

drupalcritical v1.1.1

Weekly downloads
19
License
ISC
Repository
github
Last release
6 years ago

Drupal Critical NPM version

Automated generation of Critical CSS for Drupal sites.

Note Drupal module will be released shortly, in the meantime you can use this by manually configuring which pages to proces (see example below)

npm.io

Install

$ npm install --save drupalcritical

Usage

Example:

var critical = require('drupalcritical');

var settings = {
    inline: false,
    local: true,
    dest: 'dest/',
    extract: true,
    ignore: [
      '@font-face',
      /url\(/,
      /print/,
      /animation/g,
      /interpolation/g,
      /-webkit/g,
      /-moz/g,
      /-ms/g,
      /speak/g,
      /list-style-image/g,
      /list-style-type/g
    ],
    ignoreOptions: {
      matchSelectors: true,
      matchTypes: true,
      matchDeclarationProperties: true,
      matchDeclarationValues: true,
      matchMedia: true
    },
    dimensions: [{
      height: 200,
      width: 500
    }, {
      height: 900,
      width: 1200
    }]
  };


var pages = require('./critical.json');
critical.generate(settings, pages);

Critical.json

{
  "base": "http://www.example.com",
  "pages": [
    {
      "path": "/",
      "filename": "critical-home.css"
    },
    {
      "path": "/demo",
      "filename": "critical-demo.css"
    }
  ]
}

Options

note: Not all critical options are available, the list below includes all options

NameTypeDefaultDescription
cssarray[]An array of paths to css files, or an array of Vinyl file objects.
deststring./Location of where to save the output of an operation (will be relative to base if no absolute path is set)
localstringfalseUse local (development) url to generate Critical CSS, if false it uses the given base
widthinteger900Width of the target viewport
heightinteger1300Height of the target viewport
dimensionsarray[]An array of objects containing height and width. Takes precedence over width and height if set
minifybooleanfalseEnable minification of generated critical-path CSS
extractbooleanfalseRemove the inlined styles from any stylesheets referenced in the HTML. It generates new references based on extracted content so it's safe to use for multiple HTML files referencing the same stylesheet. Use with caution. Removing the critical CSS per page results in a unique async loaded CSS file for every page. Meaning you can't rely on cache across multiple pages
inlineImagesbooleanfalseInline images
assetPathsarray[]List of directories/urls where the inliner should start looking for assets
maxImageFileSizeinteger10240Sets a max file size (in bytes) for base64 inlined images
timeoutinteger30000Sets a maximum timeout for the operation
pathPrefixstring/Path to prepend CSS assets with. You must make this path absolute if you are going to be using critical in multiple target files in disparate directory depths. (eg. targeting both /index.html and /admin/index.html would require this path to start with / or it wouldn't work.)
includearray[]Force include CSS rules. See penthouse#usage.
ignorearray[]Ignore CSS rules. See filter-css for usage examples.
ignoreOptionsobject{}Ignore options. See filter-css#options.
penthouseobject{}Configuration options for penthouse.

Changelog

v1.1.0 - 2017-11-24

  • renamed url to path
  • changed fixed filenaming to variable
1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago