Socket
Socket
Sign inDemoInstall

webpack-critical-css-inliner

Package Overview
Dependencies
266
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    webpack-critical-css-inliner

A fast webpack plugin for inlining critical (above-the-fold) css


Version published
Weekly downloads
39
increased by21.88%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

webpack-critical-css-inliner

It is a webpack plugin that inlines your critical (above-the-fold) CSS using Puppeteer.

Webpack-critical-css-inliner uses critical-css-inliner under the hood, so IT IS VERY FAST.

If you use ADAPTIVE DESIGN, webpack-critical-css-inliner is your salvation. It supports both mobile and desktop versions.

Features

  1. Extracting critical (above-the-fold) CSS.
  2. Fast inlining that CSS.
  3. Make the rest styles lazy-loaded.
  4. Handling Google Fonts.
  5. Optimize existing styles.

Installation

npm install --save-dev webpack-critical-css-inliner

// or

yarn add --dev webpack-critical-css-inliner

Docs

webpack.config.js

const WebpackCriticalCSSInliner = require('webpack-critical-css-inliner');

module.exports = {
  plugins: [
    new WebpackCriticalCSSInliner({
      // 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

// webpack.config.js
const WebpackCriticalCSSInliner = require('webpack-critical-css-inliner');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');

module.exports = {

  mode: 'production',

  entry: path.resolve(__dirname, 'src/', 'index.js'),

  output: {
    path: path.resolve(__dirname, 'dist/'),
    filename: 'webpack-critical-css-inliner.[contenthash].js'
  },

  module: {
    rules: [{
      test: /\.css$/,
      use: [
        MiniCssExtractPlugin.loader,
        'css-loader'
      ]
    }]
  },

  plugins: [
    new HtmlWebpackPlugin(),

    new MiniCssExtractPlugin(),

    new WebpackCriticalCSSInliner({
      base: 'dist/',
      src: 'index.html',
      target: 'index-critical.html',
      inlineGoogleFonts: true,
      minify: true,
      ignoreStylesheets: [/bootstrap/],
      whitelist: /#foo|\.bar/
    })
  ]
}

License

MIT license

Keywords

FAQs

Last updated on 01 Jan 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc