kdu-demi v0.12.5
Kdu Demi
Usage
Install this as your plugin's dependency:
npm i kdu-demi
# or
yarn add kdu-demi
Add kdu
and @kdujs/composition-api
to your plugin's peer dependencies to specify what versions you support.
{
"dependencies": {
"kdu-demi": "latest"
},
"peerDependencies": {
"@kdujs/composition-api": "^1.1.0-rc.0",
"kdu": "^2.0.0 || >=3.0.0"
},
"peerDependenciesMeta": {
"@kdujs/composition-api": {
"optional": true
}
},
"devDependencies": {
"kdu": "^3.0.0" // or "^2.6.0" base on your preferred working environment
},
}
Import everything related to Kdu from it, it will redirect to kdu@2
+ @kdujs/composition-api
or kdu@3
based on users' environments.
import { ref, reactive, defineComponent } from 'kdu-demi'
Publish your plugin and all is done!
When using with Wite, you will need to opt-out the pre-bundling to get
kdu-demi
work properly by// wite.config.js export default defineConfig({ optimizeDeps: { exclude: ['kdu-demi'] } })
Extra APIs
kdu Demi
provides extra APIs to help distinguish users' environments and to do some version-specific logic.
isKdu2
isKdu3
import { isKdu2, isKdu3 } from 'kdu-demi'
if (isKdu2) {
// Kdu 2 only
} else {
// Kdu 3 only
}
Kdu2
To avoid bringing in all the tree-shakable modules, we provide a Kdu2
export to support access to Kdu 2's global API.
import { Kdu2 } from 'kdu-demi'
if (Kdu2) {
Kdu2.config.ignoredElements.push('x-foo')
}
install()
Composition API in Kdu 2 is provided as a plugin and needs to be installed on the Kdu instance before using. Normally, kdu-demi
will try to install it automatically. For some usages where you might need to ensure the plugin gets installed correctly, the install()
API is exposed to as a safe version of Kdu.use(CompositionAPI)
. install()
in the Kdu 3 environment will be an empty function (no-op).
import { install } from 'kdu-demi'
install()
CLI
Manually Switch Versions
To explicitly switch the redirecting version, you can use these commands in your project's root.
npx kdu-demi-switch 2
# or
npx kdu-demi-switch 3
Package Aliasing
If you would like to import kdu
under an alias, you can use the following command
npx kdu-demi-switch 2 kdu2
# or
npx kdu-demi-switch 3 kdu3
Then kdu-demi
will redirect APIs from the alias name you specified, for example:
import * as Kdu from 'kdu3'
var isKdu2 = false
var isKdu3 = true
var Kdu2 = undefined
export * from 'kdu3'
export {
Kdu,
Kdu2,
isKdu2,
isKdu3,
}
Auto Fix
If the postinstall
hook doesn't get triggered or you have updated the Kdu version, try to run the following command to resolve the redirecting.
npx kdu-demi-fix
License
MIT License © 2022 NKDuy