lisonge / vite-plugin-monkey

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

开发模式下怎么引入@require的脚本资源 #76

Closed ZhaoCabin closed 1 year ago

ZhaoCabin commented 1 year ago

比如有些hook的方法,我需要让他在 @require阶段就导入

我尝试使用window来传递模块 window.cbAjaxHooker = function() {)()

但实际项目中window和油猴脚本的window隔离了,window.cbAjaxHooker为undefined

我猜测应该是调试模式采用插入script标签的方式,导致无法识别@require资源,window也没法传递

请问这种情况我应该怎么在项目中使用 @require的方法

lisonge commented 1 year ago

window也没法传递

README.md##esm-usage

import { monkeyWindow } from '$';
console.log(monkeyWindow.cbAjaxHooker)
ZhaoCabin commented 1 year ago

厉害,厉害,我就说这么厉害的框架不应该没有考虑这个的问题的