🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

webpack-critical-css-inliner

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

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

1.3.0
latest
Source
npm
Version published
Weekly downloads
47
9.3%
Maintainers
1
Weekly downloads
 
Created
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

  • Extracting critical (above-the-fold) CSS.
  • Fast inlining that CSS.
  • Make the rest styles lazy-loaded.
  • Handling Google Fonts.
  • 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

webpack

FAQs

Package last updated on 01 Jan 2023

Did you know?

Socket

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