lisonge / vite-plugin-monkey

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

请问naive-ui这个ui库该怎么用externalGlobals #170

Closed lvzhenbo closed 4 months ago

lvzhenbo commented 4 months ago

我尝试使用'naive-ui': cdn.staticfile('NaiveUi', 'index.prod.js'),但是浏览器报下面的错误

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'defineComponent')
    at userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:20:9476
    at userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:20:161
    at Proxy.<anonymous> (userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:20:233)
    at wt (<anonymous>:9:89)
    at userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:1:88
    at window.__f__lxynzlxz.r36 (userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:1:420)
    at wt (<anonymous>:9:89)
    at o (<anonymous>:81:234)
    at <anonymous>:84:176
    at v (<anonymous>:78:231)
lvzhenbo commented 4 months ago

然后,这个ui库在dev下浏览器控制台会报一大堆vue props类型不对的警告 我的项目库https://github.com/lvzhenbo/115-plus

lisonge commented 4 months ago

这个ui库该怎么用externalGlobal

https://github.com/lisonge/vite-plugin-monkey?tab=readme-ov-file#mixed-iife-and-umd-at-require

'naive-ui': cdn.staticfile('naive', 'dist/index.prod.js')

这个ui库在dev下浏览器控制台会报一大堆vue props类型不对的警告

https://github.com/tusen-ai/naive-ui/issues

lvzhenbo commented 4 months ago

我试了试又报了另一个错误

Uncaught (in promise) ReferenceError: NaiveUi is not defined
    at Proxy.<anonymous> (userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:23:17)
    at wt (<anonymous>:9:89)
    at userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:1:88
    at window.__f__lxyo02e1.wvd (userscript.html?name=115%252B.user.js&id=4c2a40ea-c38b-4b19-9a89-b5b225cfc825:1:420)
    at wt (<anonymous>:9:89)
    at o (<anonymous>:81:234)
    at <anonymous>:84:176
    at v (<anonymous>:78:231)

配置

externalGlobals: {
          vue: cdn
            .jsdelivr('Vue', 'dist/vue.global.prod.js')
            .concat(util.dataUrl(';window.Vue=Vue;')),
          'naive-ui': cdn.staticfile('NaiveUi', 'index.prod.js'),
          xgplayer: cdn.jsdelivr('Player', 'dist/index.min.js'),
          'xgplayer-hls.js': cdn.jsdelivr('HlsJsPlugin', 'dist/index.min.js'),
          'big-integer': cdn.staticfile('bigInt', 'BigInteger.min.js'),
          'crypto-js': cdn.staticfile('CryptoJS', 'crypto-js.min.js'),
        },

然后,那个警告问题,我只有在使用这个库的时候才遇到,其他都没遇见过,所以才说,虽然不影响开发就是控制台里比较烦

lisonge commented 4 months ago

image

lvzhenbo commented 4 months ago

哦,是我眼瞎,非常感谢解答,我支付宝给了30块钱支持了一下

lisonge commented 4 months ago

我支付宝给了30块钱支持了一下

已收到,感觉你对我的开源工作的支持