本頁面指的是 src/uninstall.js
檔案,該檔案會在 App Extension 解除安裝時執行。並非所有 App Extension 都需要解除安裝 – 這是一個可選步驟。
檔案基本結構範例
// can be async
export default function (api) {
// props and methods for "api" Object
// are described below
}
content_paste
api.engine
包含正在使用的 Quasar CLI 引擎 (字串)。範例:@quasar/app-vite
或 @quasar/app-webpack
。
api.hasVite
布林值 - 是否正在 @quasar/app-vite
上執行。
api.hasWebpack
布林值 - 是否正在 @quasar/app-webpack
上執行。
api.extId
包含此 App Extension 的 ext-id
(字串)。
api.prompts
是一個物件,其中包含此 App Extension 安裝時的 prompts 回答。有關 prompts 的更多資訊,請查看 Prompts API。
api.resolve
解析此 App Extension 正在執行的應用程式內的路徑。無需匯入 path
並自行解析路徑。
// resolves to root of app
api.resolve.app('src/my-file.js')
// resolves to root/src of app
api.resolve.src('my-file.js')
// resolves to root/public of app
// (@quasar/app-webpack v3.4+ or @quasar/app-vite v1+)
api.resolve.public('my-image.png')
// resolves to root/src-pwa of app
api.resolve.pwa('some-file.js')
// resolves to root/src-ssr of app
api.resolve.ssr('some-file.js')
// resolves to root/src-cordova of app
api.resolve.cordova('config.xml')
// resolves to root/src-electron of app
api.resolve.electron('some-file.js')
// resolves to root/src-bex of app
api.resolve.bex('some-file.js')
content_paste
api.appDir
包含此 App Extension 正在執行的應用程式根目錄的完整路徑 (字串)。
api.hasTypescript@quasar/app-vite 1.6+ @quasar/app-webpack 3.11+
/**
* @return {Promise<boolean>} host project has Typescript active or not
*/
await api.hasTypescript()
content_paste
api.hasLint@quasar/app-vite 1.6+ @quasar/app-webpack 3.11+
/**
* @return {Promise<boolean>} host project has ESLint or not
*/
await api.hasLint()
content_paste
api.getStorePackageName@quasar/app-vite 1.6+ @quasar/app-webpack 3.11+
/**
* @return {Promise<string|undefined>} 'pinia' | 'vuex' | undefined
*/
await api.getStorePackageName()
content_paste
api.getNodePackagerName@quasar/app-vite 1.6+ @quasar/app-webpack 3.11+
/**
* @return {Promise<'npm' | 'yarn' | 'pnpm' | 'bun'>}
*/
await api.getNodePackagerName()
content_paste
api.hasPackage
判斷主機應用程式中是否透過語意化版本條件安裝了某些套件。
語意化版本條件範例:'1.x || >=2.5.0 || 5.0.0 - 7.2.3'
。
/**
* @param {string} packageName
* @param {string} (optional) semverCondition
* @return {boolean} package is installed and meets optional semver condition
*/
if (api.hasPackage('vuelidate')) {
// hey, this app has it (any version of it)
}
if (api.hasPackage('quasar', '^2.0.0')) {
// hey, this app has Quasar UI v2 installed
}
content_paste
api.hasExtension
檢查是否已安裝另一個應用程式擴充功能。
/**
* Check if another app extension is installed
*
* @param {string} extId
* @return {boolean} has the extension installed.
*/
if (api.hasExtension(extId)) {
// hey, we have it
}
content_paste
api.getPackageVersion
取得主機應用程式套件的版本。
/**
* @param {string} packageName
* @return {string|undefined} version of app's package
*/
console.log( api.getPackageVersion(packageName) )
// output examples:
// 1.1.3
// undefined (when package not found)
content_paste
api.removePath
從應用程式專案資料夾中移除檔案或資料夾 (App Extension 已安裝且不再需要)。
請注意,不要刪除會破壞開發人員應用程式的檔案。
檔案或資料夾的路徑需要相對於專案的根資料夾。
/**
* @param {string} __path
*/
api.removePath('my-folder')
content_paste
以上範例從應用程式的根目錄中刪除 "my-folder"。
api.getPersistentConf
取得此擴充功能的內部持久設定。如果沒有,則傳回空物件。
/**
* @return {object} cfg
*/
api.getPersistentConf()
content_paste
api.onExitLog
在 App CLI 完成解除安裝 App Extension 並即將結束時,新增要列印的訊息。可以多次呼叫以註冊多個結束日誌。
/**
* @param {string} msg
*/
api.onExitLog('Thanks for having used my extension')
content_paste