Skip to content
解决 vite 打包报错 @charset

报错内容:

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

报错原因:

scss 文件中有中文

解决方案:

修改 vite.config.js,加入以下内容

javascript
css: {
  postcss: {
    plugins: [
      {
        postcssPlugin: "internal:charset-removal",
        AtRule: {
          charset: (atRule) => {
            if (atRule.name === "charset") {
              atRule.remove();
            }
          },
        },
      },
    ],
  },
},
Release time: 3/1/2022, 3:42:43

Last updated:

⟣ Growing, with you. ⟢