注入Quasar插件

本指南适用于要确保将Quasar插件注入宿主应用程序的情况,因为您需要依靠它来运行自己的应用扩展。

TIP

为了创建应用扩展项目文件夹,请首先阅读开发指南>简介.

完整例子

要查看我们将构建的示例,请转到完整示例, 它是此应用程序扩展的一个GitHub存储库。

我们只需要/index.js脚本,因为我们可以使用索引API从宿主应用程序配置quasar.config.js来包含我们的需要Quasar插件。

.
├── package.json
└── src
    └── index.js              # 在索引API中描述

/index.js看起来像这样:

// 文件: /index.js
module.exports = function (api) {
  // (可选!)
  // Quasar 兼容性检查; 您可能需要硬性依赖性,
  // 例如最低版本的“quasar”软件包
  // 或最低版本的Quasar App CLI
  api.compatibleWith('quasar', '^2.0.0')
  
  if (api.hasVite === true) {
    api.compatibleWith('@quasar/app-vite', '^1.0.0-beta.0')
  }
  else { // api.hasWebpack === true
    api.compatibleWith('@quasar/app-webpack', '^3.0.0')
  }

  // 在这里,我们扩展了/quasar.config.js,
  // 因此我们可以添加一个启动文件来注册我们的新UI指令; 
  // “extendConf”将在下面定义(请继续阅读教程)
  api.extendQuasarConf(extendConf)
}

上面相同的文件中的“extendConf”方法:

// 文件: /index.js
function extendConf (conf) {
  // 我们推送到/quasar.config.js > framework > plugins:
  conf.framework.plugins.push('AppVisibility')
}