
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
html-inline-css-rspack-plugin
Advanced tools
☄️ A rspack plugin for convert external stylesheet to embedded stylesheet, aka document stylesheet
Forked the html-inline-css-webpack-plugin and modified it to be compatible with rspack
Convert external stylesheet to embedded stylesheet, aka document stylesheet.
<link rel="stylesheet" /> => <style>...<style/>
Require rspack.CssExtractRspackPlugin and rspack.HtmlRspackPlugin
npm i html-inline-css-rspack-plugin -D
yarn add html-inline-css-rspack-plugin -D
// 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.
interface Config {
filter?: (fileName: string) => boolean
styleTagFactory?: (params: { style: string }) => string
leaveCSSFile?: boolean
replace?: {
target: string
position?: 'before' | 'after'
removeTarget?: boolean
}
}
filter?: (fileName: string) => boolean
Return true to make current file internal, otherwise ignore current file. Include both css file and html file name.
...
new HTMLInlineRspackPlugin({
filter(fileName) {
return fileName.includes('main');
},
}),
...
styleTagFactory?: (params: { style: string }) => string
Used to customize the style tag.
...
new HTMLInlineRspackPlugin({
styleTagFactory({ style }) {
return `<style type="text/css">${style}</style>`;
},
}),
...
if true, it will leave CSS files where they are when inlining
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>
A target for adding the internal style sheet
Add internal style sheet before/after the target
if true, it will remove the target from the output HTML
Please note that HTML comment is removed by default by the
html-webpack-pluginin production mode. #16
<head>
<!-- inline_css_plugin -->
<style>
/* some hard code style */
</style>
</head>
...
new HTMLInlineRspackPlugin({
replace: {
removeTarget: true,
target: '<!-- inline_css_plugin -->',
},
}),
...
<head>
<style>
/* style from *.css files */
</style>
<style>
/* some hard code style */
</style>
</head>
FAQs
☄️ A rspack plugin for convert external stylesheet to embedded stylesheet, aka document stylesheet
We found that html-inline-css-rspack-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.