Socket
Socket
Sign inDemoInstall

grunt-inlinestyles

Package Overview
Dependencies
51
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    grunt-inlinestyles

Inline critical CSS into the HTML header


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
7.24 MB
Created
Weekly downloads
 

Readme

Source

grunt-inlinestyles

A Grunt plugin to inline a selected CSS file. Ideal for inlining critical CSS.

This will take a HTML stylesheet link and inline the target CSS.

This means that:

<link rel="stylesheet" href="/css/stylesheet.css" data-inline="true">

will become:

<style>h1{font-style:italic}</style>

This module does not inline javascript, images or fonts.

Getting Started

This plugin requires Grunt.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-inlinestyles --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-inlinestyles');

The "inlinestyles" task

Overview

In your project's Gruntfile, add a section named inlinestyles to the data object passed into grunt.initConfig().

grunt.initConfig({
  inlinestyles: {
    options: {
      // Task-specific options go here.
      basepath: './',
      minify: true,
      tag: '[data-inline="true"]'
    },
    your_target: {
      // Target-specific file lists and/or options go here.
      files: {
        'destination.html': 'source.html'
      }
    },
  },
})

Options

options.basepath

Type: String Default value: 'process.cwd()'

A string value that is used to indicate the root of your website. 'Absolute' CSS links are relative to this value.

options.minify

Type: boolean Default value: true

A boolean that is used to turn minification of the inlined CSS on or off.

options.tag

Type: String Default value: '[data-inline="true"]'

A string value that is used to designate a CSS link that is to be inlined.

Usage Examples

Default Options

In this example, the default options are used to inline CSS inside source.html. So if the source.html file has the content <link rel="stylesheet" href="/css/stylesheet.css" data-inline="true"> the generated result would contain <style>h1{font-style:italic}</style>

grunt.initConfig({
  inlinestyles: {
    options: {},
      files: {
        'destination.html': 'source.html'
      }
  },
})
Custom Options

In this example, custom options are used to specify a new basepath, disable CSS minification and to add a new inlining tag.

grunt.initConfig({
  inlinestyles: {
    options: {
      basepath: 'subpath',
      minify: false,
      tag: '[data-inlinethisstyle="true"]'
    },
      files: {
        'destination.html': 'source.html'
      }
  },
})

Contributing

Contributions are welcome! Hit me up via @sonniesedge

Release History

v0.0.1 Initial release

License

Copyright (c) 2014 . Licensed under the MIT license.

Keywords

FAQs

Last updated on 27 Oct 2014

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc