This commit is contained in:
Luk 2024-02-23 13:25:53 +08:00
parent 849bc8997b
commit 69257f2aa4
2 changed files with 16 additions and 6 deletions

8
coco-none.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = {
cclog () { },
ccinfo () { },
ccgood () { },
ccwarn () { },
ccerror () { },
ccdebug () { }
}

14
coco.js
View File

@ -2,12 +2,14 @@
// consola works in nodejs and browser
// chalk 和 colors 用法类似。
// in uniapp: globalThis.uni && globalThis.UniApp
// in vue: globalThis.getApp?.()?.constructor?.name === 'Vue'
// globalThis.uni // 在 web/app 里都为对象
// globalThis.UniApp // 在 web 里返回一个函数,在 app 里返回 undefined
// globalThis.getApp?.()?.constructor?.name === 'Vue' // 在 web 里 true, 在 app 里 false
// typeof(globalThis.getApp)==='function' // 在 web/app 里都为 true
module.exports =
process?.release?.name === 'node' ? require('./coco-nodejs.js')
: globalThis.window && globalThis.location ? require('./coco-browser.js')
: globalThis.uniCloud ? require('./coco-unicloud.js')
: require('./coco-app.js')
: globalThis.uniCloud ? require('./coco-unicloud.js')
: globalThis.window && globalThis.location ? require('./coco-browser.js')
: globalThis.uni && globalThis.getApp ? require('./coco-app.js')
: require('./coco-none.js')