lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.33k stars 70 forks source link

开启了minifyCss时,打包得到的css没有遵循vite构建选项里的build.cssTarget #37

Closed northsea4 closed 1 year ago

northsea4 commented 1 year ago

环境

Windows 10 Chrome v83 vite-plugin-monkey v2.10.0

简述

设置了vite构建选项build.cssTargetnpm run build后发现,HelloWorld.vue.read-the-docs的定位样式被编译为了inset:60px 0 0 260px;,而inset是chrome87才开始支持的,所以似乎是某种处理导致build.cssTarget没有生效。

vite.config.ts

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import monkey, { cdn } from 'vite-plugin-monkey';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    monkey({
      entry: 'src/main.ts',
      userscript: {
        icon: 'https://vitejs.dev/logo.svg',
        namespace: 'npm/vite-plugin-monkey',
        match: ['https://www.google.com/'],
      },
      build: {
        minifyCss: true,
        externalGlobals: {
          vue: cdn.jsdelivr('Vue', 'dist/vue.global.prod.js'),
        },
      },
    }),
  ],
  build: {
    cssTarget: 'chrome83',
  }
});

src/components/HelloWorld.vue

<style scoped>
.read-the-docs {
  color: #888;
  position: fixed;
  top: 60px;
  right: 0;
  bottom: 0;
  left: 260px;
  background: #fff;
  z-index: 1050;
  padding: 10px 20px 200px 20px;
  overflow-y: auto;
  box-shadow: -2px 2px 6px #bbbbbb;
}
</style>

麻烦大神看一下是怎么回事,感谢!

lisonge commented 1 year ago

应该是此处

https://github.com/lisonge/vite-plugin-monkey/blob/07cd87ad3f8e773553222fec8c578672bf8b699c/packages/vite-plugin-monkey/src/node/_util.ts#L278-L282

没有传递 target 导致的


我后续修复一下

lisonge commented 1 year ago

备注:类似的问题可在此处找到 esbuild#1925

lisonge commented 1 year ago

fixed by v2.10.1