vbenjs / vite-plugin-style-import

A plug-in that imports component library styles on demand.it is fast
MIT License
448 stars 59 forks source link

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

Closed wubiandaxian closed 2 years ago

wubiandaxian commented 2 years ago

环境: vite: 2.6.11 vite-plugin-style-import: 1.4.0 ant-design-vue: 3.0.0-alpha.12

vite按需加载配置:

styleImport({
        libs: [
          {
            libraryName: 'ant-design-vue',
            esModule: true,
            resolveComponent: (name) => `ant-design-vue/es/${name}`,
            resolveStyle: (name) => `ant-design-vue/es/${name}/style/index`,
          },
        ],
      }),

vite中css预处理的配置

css: {
      preprocessorOptions: {
        less: {
          charset: false,
        },
        scss: {
          charset: false,
        },
        css: {
          charset: false,
        },
      },
    },

问题: 如果打包的时候,加入了按需引入,就会报如下warning

:4004:0: warning: "@charset" must be the first rule in the file 4004 │ @charset "UTF-8"; ╵ ~~~~~~~~ :3972:0: note: This rule cannot come before a "@charset" rule 3972 │ .ant-spin.ant-spin-show-text .ant-spin-text { ╵ ^

不添加按需引入的配置打包是没有问题的。目前不知道问题出在哪,就来这提issues了

wubiandaxian commented 2 years ago

如果按需加载的配置中不写 resolveStyle,也不会报warning

wubiandaxian commented 2 years ago

vite的issues里找到了解决办法,但是我依旧不知道这是属于谁的bug

vite: build includes @charset problem.#5833

wubiandaxian commented 2 years ago

esbuild的问题: https://github.com/evanw/esbuild/issues/1862