npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-inline-css-rspack-plugin

v1.11.3

Published

☄️ A rspack plugin for convert external stylesheet to embedded stylesheet, aka document stylesheet

Downloads

140

Readme

html-inline-css-rspack-plugin

Forked the html-inline-css-webpack-plugin and modified it to be compatible with rspack


MIT Licence PRs Welcome Total downloads npm version

Convert external stylesheet to embedded stylesheet, aka document stylesheet.

<link rel="stylesheet" /> => <style>...<style/>

Require rspack.CssExtractRspackPlugin and rspack.HtmlRspackPlugin

Install

NPM

npm i html-inline-css-rspack-plugin -D

Yarn

yarn add html-inline-css-rspack-plugin -D

Minimal example

// const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// const HtmlWebpackPlugin = require('html-webpack-plugin');
// const HTMLInlineCSSWebpackPlugin = require("html-inline-css-rspack-plugin").default;
import { rspack } from '@rspack/core';
import { HTMLInlineRspackPlugin } from 'html-inline-css-rspack-plugin'

module.exports = {
  plugins: [
    // new MiniCssExtractPlugin({
    //   filename: "[name].css",
    //   chunkFilename: "[id].css"
    // }),
    // new HtmlWebpackPlugin(),
    new rspack.CssExtractRspackPlugin({}),
    new rspack.HtmlRspackPlugin(options);
    new HTMLInlineRspackPlugin(),
  ],
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [rspack.CssExtractRspackPlugin.loader, 'css-loader'],
        type: 'javascript/auto',
      },
    ]
  }
}

Keep the original config as html-inline-css-webpack-plugin.

Config

interface Config {
  filter?: (fileName: string) => boolean
  styleTagFactory?: (params: { style: string }) => string
  leaveCSSFile?: boolean
  replace?: {
    target: string
    position?: 'before' | 'after'
    removeTarget?: boolean
  }
}

filter(optional)

filter?: (fileName: string) => boolean

Return true to make current file internal, otherwise ignore current file. Include both css file and html file name.

example
...
new HTMLInlineRspackPlugin({
  filter(fileName) {
    return fileName.includes('main');
  },
}),
...

styleTagFactory(optional)

styleTagFactory?: (params: { style: string }) => string

Used to customize the style tag.

example
...
  new HTMLInlineRspackPlugin({
    styleTagFactory({ style }) {
      return `<style type="text/css">${style}</style>`;
    },
  }),
...

leaveCSSFile(optional)

if true, it will leave CSS files where they are when inlining

replace(optional)

replace?: {
  target: string
  position?: 'before' | 'after' // default is 'before'
  removeTarget?: boolean // default is false
}

A config for customizing the location of injection, default will add internal style sheet before the </head>

target

A target for adding the internal style sheet

position(optional)

Add internal style sheet before/after the target

removeTarget(optional)

if true, it will remove the target from the output HTML

Please note that HTML comment is removed by default by the html-webpack-plugin in production mode. #16

example
<head>
    <!-- inline_css_plugin -->
    <style>
        /* some hard code style */
    </style>
</head>
...
  new HTMLInlineRspackPlugin({
    replace: {
      removeTarget: true,
      target: '<!-- inline_css_plugin -->',
    },
  }),
...
output:
<head>
    <style>
        /* style from *.css files */
    </style>
    <style>
        /* some hard code style */
    </style>
</head>