Skip to content

tjdav/coralite-plugin-inline-css

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coralite Inline CSS Plugin

A plugin for Coralite that converts stylesheet link tags with the inline-css attribute into <style> elements in the HTML output, allowing you to use CSS without external files.

Features

  • Inlines CSS from <link> tags into <style> elements.
  • Optional options to:
    • Transform @import rules to inline content.
    • Minify CSS by removing comments and unnecessary whitespace.

Installation

Install the plugin via npm:

npm install coralite-plugin-inline-css

Usage

1. Configure Coralite

Create a coralite.config.js file with the plugin configuration:

// coralite.config.js
import inlineCSS from 'coralite-plugin-inline-css';

export default {
  plugins: [inlineCSS({
    atImport: true,
    minify: true
  })]
};

2. Use in HTML

Add the inline-css attribute to your <link> tags:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="name" content="coralite">
  <meta name="description" content="look mum, no database!">
  <!-- inline-css attribute is needed to convert link tag to style with inline css -->
  <link rel="stylesheet" href="css/styles.css" inline-css>
  <title>Blog posts</title>
</head>
<body>

</body>
</html>

3. Output

The plugin will transform your <link> tag into a <style> block with the inlined CSS:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="name" content="coralite">
  <meta name="description" content="look mum, no database!">
  <style>
    .body {
      background-color: rebeccapurple;
      color: white;
    }
  </style>
  <title>Blog posts</title>
</head>
<body>

</body>
</html>

Options

/**
 * @typedef {Object} InlineCSSOptions
 * @property {boolean} [atImport=false] - Transform @import rules to inlining content.
 * @property {boolean} [minify=false] - Minify CSS by removing comments and unnecessary whitespace from CSS files.
 */

Example Configuration

// coralite.config.js
import inlineCSS from 'coralite-plugin-inline-css';

export default {
  plugins: [inlineCSS({
    atImport: true,
    minify: true
  })]
};

About

A simple plugin for Coralite that inline's CSS files

Resources

License

Stars

Watchers

Forks

Packages

No packages published