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

watch 模式下,external依赖产生的require会错误的增生 #27

Closed pionxzh closed 1 year ago

pionxzh commented 1 year ago

使用以下 config 搭配 vite build --watch

monkey({
  build: {
      externalGlobals: {
          'sentinel-js': cdn.cdnjs('sentinel', 'sentinel.min.js'),
      }
  }
})

触发多次rebuild后会得到

// ==UserScript==
// @name         知乎助手
// @namespace    pionxzh
// @version      1.0.0
// @author       pionxzh
// @description  自动屏蔽来自黑名单的所有评论与文章
// @license      MIT
// @icon         https://static.zhihu.com/heifetz/favicon.ico
// @match        *.zhihu.com/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

配置也可以参考 /pionxzh/userscripts/packages/zhihu/vite.config.ts

lisonge commented 1 year ago

一般情况不用 vite build --watch,都是直接用 vite serve

不过你说的问题确实需要解决

lisonge commented 1 year ago

fixed by v2.7.2

lisonge commented 1 year ago

由于在 v2.7.2 不小心移动了 viteConfig.build.rollupOptions.inputapply: 'build', 的子插件里

这导致 pre-bundling 未在 vite serve 下启用

已在 v2.7.3 中修复