Inline critical CSS in HTML page
npm install critical-css-inliner).
|
|
sh
npm install --save-dev critical-css-inliner
// or
yarn add --dev critical-css-inliner
`
Docs
`js
const criticalCSSInliner = require('critical-css-inliner');
await criticalCSSInliner({
// Your entrypoint
base: 'dist/',
// HTML source file
src: 'index.html',
// HTML target file
target: 'index-critical.html',
// Add Google Fonts to critical CSS
inlineGoogleFonts: true,
// Minify all styles
minify: true,
// ignore styles from the following stylesheets
ignoreStylesheets: [/bootstrap/],
// inline styles with the following CSS rules
whitelist: /#foo|\.bar/
});
`
Example
`js
const criticalCSSInliner = require('critical-css-inliner');
(async () => {
await criticalCSSInliner({
base: 'dist/',
src: 'index.html',
target: 'index-critical.html',
inlineGoogleFonts: true,
minify: true,
ignoreStylesheets: [/bootstrap/],
whitelist: /#foo|\.bar/
});
})();
`
---
Usage
$3
Pass options to criticalCSSInliner({ ... }).
$3
`> ``