extract-css-core

0.1.0 • Public • Published

extract-css-core

Extract all CSS from a given url, both server side and client side rendered.

NPM Version Weekly downloads Build Status Known Vulnerabilities Dependencies Status Dependencies Status XO code style Project: Wallace

Problem, solution and shortcomings

Problem

Existing packages like get-css look at a server-generated piece of HTML and get all the <link> and <style> tags from it. This works fine for 100% server rendered pages, but apps that employ style injection with JavaScript will not be covered.

Solution

This module uses an instance of Chromium to render a page. This has the benefit that most of the styles can be rendered, even when generated by JavaScript. The Puppeteer CSSCoverage API is the power behind finding most of the CSS.

Shortcomings

Currently, there is no solution to get the CSS from modules that use Styled Components or something similar. Any help resolving this issue will be very much appreciated. Please contribute to the relevant GitHub issue.

Installation

npm install extract-css-core

# Or with Yarn
yarn add extract-css-core

Usage

const extractCss = require('extract-css-core')

extractCss('http://www.projectwallace.com').then(css => console.log(css))

API

extractCss(url, [options])

Extract CSS from a page. Returns a Promise that contains the CSS as a single String.

Options

Type: Object

debug

Type: Boolean Default: false

Set to true if you want a Chromium window to open as it works to get all the CSS from the page.

waitUntil

Type: String Default: networkidle2

Can be any value as provided by the Puppeteer docs.

customBrowser

Type: Object Default: null

This is useful if you want to run extract-css on AWS Lambda for example.

executablePath

Type: String Default: null

Pass in the executable path for a custom Chromium instance.

customPuppeteer

Type: Object Default: null

You probably want to provide puppeteer-core for a custom browser instead of puppeteer which brings it's own Chromium instance.

Related

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.03,514latest

Version History

VersionDownloads (Last 7 Days)Published
3.0.03,514
2.3.15
2.3.01
2.2.01
2.1.01
2.0.01
2.0.0-beta.10
1.1.01
1.0.01
0.3.01
0.2.01
0.1.01

Package Sidebar

Install

npm i extract-css-core@0.1.0

Version

0.1.0

License

MIT

Unpacked Size

8.71 kB

Total Files

4

Last publish

Collaborators

  • bartveneman