- Notifications
You must be signed in to change notification settings - Fork22
☄️ A webpack plugin to convert external stylesheets into embedded stylesheets
License
runjuu/html-inline-css-webpack-plugin
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Convert external stylesheet to embedded stylesheet, aka document stylesheet.
<link rel="stylesheet" /> => <style>...<style/>
Requiremini-css-extract-plugin andhtml-webpack-plugin
npm i html-inline-css-webpack-plugin -D
yarn add html-inline-css-webpack-plugin -D
constMiniCssExtractPlugin=require("mini-css-extract-plugin");constHtmlWebpackPlugin=require('html-webpack-plugin');constHTMLInlineCSSWebpackPlugin=require("html-inline-css-webpack-plugin").default;module.exports={plugins:[newMiniCssExtractPlugin({filename:"[name].css",chunkFilename:"[id].css"}),newHtmlWebpackPlugin(),newHTMLInlineCSSWebpackPlugin(),],module:{rules:[{test:/\.css$/,use:[MiniCssExtractPlugin.loader,"css-loader"]}]}}
interfaceConfig{filter?:(fileName:string)=>booleanstyleTagFactory?:(params:{style:string})=>stringleaveCSSFile?:booleanreplace?:{target:stringposition?:'before'|'after'removeTarget?:boolean}}
filter?:(fileName:string)=>boolean
Returntrue
to make current file internal, otherwise ignore current file. Include both css file and html file name.
...newHTMLInlineCSSWebpackPlugin({filter(fileName){returnfileName.includes('main');},}),...
styleTagFactory?:(params:{style:string})=>string
Used to customize the style tag.
...newHTMLInlineCSSWebpackPlugin({styleTagFactory({ style}){return`<style type="text/css">${style}</style>`;},}),...
iftrue
, 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 sheetbefore
/after
thetarget
iftrue
, it will remove thetarget
from the output HTML
Please note that HTML comment is removed by default by the
html-webpack-plugin
in production mode.#16
<head><!-- inline_css_plugin --><style>/* some hard code style */</style></head>
...newHTMLInlineCSSWebpackPlugin({replace:{removeTarget:true,target:'<!-- inline_css_plugin -->',},}),...
<head><style>/* style from *.css files */</style><style>/* some hard code style */</style></head>
About
☄️ A webpack plugin to convert external stylesheets into embedded stylesheets
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.