CSS charset rule is ignored in production mode.
See original GitHub issueWhen .scss file holds some non-ASCII character, then sass is adding @charset "UTF-8";
row to the begining of output css file. It works fine for “development” webpackge mode, but in “production” mode this css rule is not being added.
- Operating System: Windows 10
- Node Version: 14.17.0
- NPM Version: 6.14.13
- webpack Version: ^5.11.1
- sass-loader Version: ^12.1.0
- sass: ^1.35.1
Expected Behavior
With webpack “production” mode, css charset rule is also added to output css file.
Actual Behavior
With webpack “production” mode, css charset rule is not being added.
Code
// webpack.config.js
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const mode = process.env.NODE_ENV || "development";
const target = process.env.NODE_ENV === "production" ? "browserslist" : "web";
module.exports = {
mode: mode,
plugins: [new MiniCssExtractPlugin()],
module: {
rules: [{
test: /\.(s[ac]|c)ss$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"sass-loader"
]
},{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
}],
},
target: target,
devtool: "source-map",
devServer: { contentBase: "./dist" },
};
How Do We Reproduce?
Follow instructions in this repo - https://github.com/scream87/css-charset-with-sass-loader
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
charset - CSS: Cascading Style Sheets - MDN Web Docs
The @charset CSS at-rule specifies the character encoding used in the style sheet. It must be the first element in the style sheet...
Read more >Allow removing @charset atrule with expanded OutputStyle
We're producing valid CSS that's as compatible as possible. ... it cause warning: "@charset" must be the first rule in the file on...
Read more >How can I prevent Webpack 5 (or one of its plugins) from ...
If I switch the mode to none or development , then the exported CSS is not minified (i.e., line breaks are there), and...
Read more >CSS Syntax Module Level 3 - W3C
A number of things you can do in CSS that would produce a valid @charset rule (if one existed), such as using multiple...
Read more >MiniCssExtractPlugin - webpack
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); module.exports = { plugins: [new MiniCssExtractPlugin()], module: { rules: [ { test: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@alexander-akait Was the bug reported in
dart-sass
/sass
?I found this issue: https://github.com/sass/dart-sass/issues/1387 And the author claims removing
@charset
incompressed
isn’t a bug. Can you relate?CC: @scream87
Ok, I see. Thanks for the operative and quick reaction. Since it is not
sass-loader
bug, I am closing this issue.