a webpack|rspack plugin which add charset to css file
npm install add-charset-webpack-plugin✅ Works with Webpack 4 / 5 and Rspack.
✅ Supports CommonJS and ESM import styles.
✅ Automatically adds @charset to the first line of every emitted .css file.
``bash`
npm install add-charset-webpack-plugin
`js
/* webpack.config.js or rspack.config.js /
const AddCharsetWebpackPlugin = require("add-charset-webpack-plugin");
module.exports = {
plugins: [
new AddCharsetWebpackPlugin({
charset: "utf-8"
})
]
}
`
js
/* webpack.config.mjs or rspack.config.mjs /
import AddCharsetWebpackPlugin from "add-charset-webpack-plugin";export default {
plugins: [
new AddCharsetWebpackPlugin({
charset: "utf-8"
})
]
};
`This will add charset declare in the first line of all the final css files, example as following
`css
@charset "utf-8";html {
margin: 0,
padding: 0
}
body {
min-width: 960px;
background: #FFFFFF;
font-size: 14px;
}
...
`Options
You can pass a hash of configuration options to add-charset-webpack-plugin.Allowed values are as follows:|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|
charset|{String}|utf-8|To display an HTML page correctly, a web browser must know which character set to use, Defaults to utf-8`|Copyright (c) 2021-present VN666
MIT (see LICENSE)