Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: "@charset" must be the first rule in the file #5519

Closed
7 tasks done
mxp131011 opened this issue Nov 3, 2021 · 2 comments
Closed
7 tasks done

warning: "@charset" must be the first rule in the file #5519

mxp131011 opened this issue Nov 3, 2021 · 2 comments

Comments

@mxp131011
Copy link

Describe the bug

vite build hint warning: "@charset" must be the first rule in the file
image

Reproduction

{
 css: { preprocessorOptions: { scss: { additionalData: `@use "@/styles/index.scss" as *;` } } },
       
 build: {
            cssCodeSplit: true, // 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
            sourcemap: false, // 构建后是否生成 source map 文件。如果为 true,将会创建一个独立的 source map 文件
            target: 'modules', // 设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——'modules'  还可设置为 'es2015' 'es2016'等
            chunkSizeWarningLimit: 550, // 单位kb  打包后文件大小警告的限制 (文件大于此此值会出现警告)
            assetsInlineLimit: 4096, // 单位字节(1024等于1kb) 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项。
            minify: 'terser', // 'terser' 相对较慢,但大多数情况下构建后的文件体积更小。'esbuild' 最小化混淆更快但构建后的文件相对更大。
            terserOptions: {
                compress: {
                    drop_console: true, // 生产环境去除console
                    drop_debugger: true // 生产环境去除debugger
                }
            },
            rollupOptions: {
                output: {
                    manualChunks: { // 拆分代码
                        'vue': ['vue', 'vue-router', 'vuex'], // 如果打包有BUG请屏蔽
                        'element-plus': ['element-plus'],
                        'echarts': ['echarts'],
                        'xlsx': ['xlsx']
                    }
                }
            }
        }
}```

### System Info

```shell
System:
    OS: Windows 10 10.0.22000
    CPU: (4) x64 Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Memory: 10.14 GB / 15.94 GB
  Binaries:
    Node: 16.11.1 - F:\IDE\nodejs\node.EXE
    npm: 8.1.2 - F:\IDE\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (95.0.1020.40)
    Internet Explorer: 11.0.22000.120

Used Package Manager

npm

Logs

warnings when minifying css:
 > <stdin>:9:0: warning: "@charset" must be the first rule in the file
    9 │ @charset "UTF-8";~~~~~~~~
   <stdin>:2:0: note: This rule cannot come before a "@charset" rule
    2 │ .svg-icon[data-v-77dc9f44] {
      ╵ ^

Validations

@yinchengnuo
Copy link

vite.config:
css: { preprocessorOptions: { scss: { charset: false } } }

@mxp131011
Copy link
Author

Thank you. That's very useful

@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants