应用扩展是一种轻松注入复杂(或简单)库的方法,其中包含各种依赖、启动文件、模板和自定义逻辑。它们可以扩展 webpack(quasar.config
文件),将外部 UI 组件与核心紧密耦合,甚至可以使用 Quasar CLI 注册新命令。它们可以与 quasar dev
一起运行,并可以完全访问当前运行的 ctx
(上下文)。
¥App Extensions are a way to painlessly inject complicated (or simple) libraries with a variety of dependencies, boot files, templates and custom logic. They can extend webpack, the quasar.config
file, tightly couple external UI components to core, and even register new commands with the Quasar CLI. They can be run with quasar dev
and have complete access to the current live ctx
(context).
这些开发模式实际上打开了闸门,使 Quasar 成为目前最具扩展性和最强大的框架之一。 - 现在,只有你的想象力和创新能力才能限制你。本页将向你介绍应用扩展的使用方法。
¥The patterns for development literally open the floodgates to making Quasar one of the most extensible and powerful frameworks out there - now limited only by your imagination and innovation. This page will introduce you to the usage of App Extensions.
警告
应用扩展专为 Quasar CLI 设计。这意味着你将无法安装它们,也无法使用 Quasar Vite 插件或在 UMD 环境中运行它们。
¥App Extensions are designed specifically for Quasar CLI only. This means that you will not be able to install them or run them with the Quasar Vite plugin or in UMD environments.
应用扩展能做什么?(What can an App Extension do?)
¥What can an App Extension do?
使用新命令增强 CLI 行为
¥Enhance CLI behavior with new commands
制作一个 Quasar UI 插件
¥Make a Quasar UI plug-in
安装配套应用
¥Install an accompanying application
创建和共享自定义组件
¥Create and share a custom component
创建并共享添加到框架或其他应用的功能
¥Create and share added features to the framework or other applications
构建、启动和控制 API 服务器
¥Build, launch and control an API server
钩住、组合和扩展 Quasar 核心组件
¥Hook, combine and extend Quasar core components
根据 Quasar 环境之外的动态变化值修改代码
¥Modify code based on dynamically changing values that sit outside of the Quasar environment
创建和管理平台特定接口的抽象
¥Create and manage abstractions of platform specific interfaces
…以及更多其他内容
¥… and a whole lot more
应用扩展取代了创建自定义入门套件的需要。你在官方入门套件之上添加的任何内容都可以以应用扩展的形式提供。这也消除了将非官方入门套件与官方入门套件保持同步的维护开销,因此我们可以确保每位开发者都能获得最新、最好的 Quasar 规范。
¥App Extensions replace the need to create custom starter kits. Anything you add on top of the official starter kit can come in the form of an App Extension. This also eliminates maintenance overhead of keeping unofficial starter kits up to date with the official one and so we can ensure that every developer will always get the latest and greatest Quasar specs out of the box.
应用扩展扩展 ID(App Extension ext-id)
¥App Extension ext-id
所有应用扩展都必须在其名称前添加 quasar-app-extension-
前缀。此前缀后的所有内容均视为其简称。在整个文档中,我们将其称为 ext-id
。
¥All App Extensions must prefix their name with quasar-app-extension-
. Everything that follows after this prefix is considered to be the short alias of it. We call this the ext-id
throughout the documentation.
示例:
¥Example:
quasar-app-extension-awesomeness
的 ext-id 是awesomeness
¥ext-id for
quasar-app-extension-awesomeness
isawesomeness
@some-npm-org/quasar-app-extension-awesomeness
的 ext-id 是@some-npm-org/awesomeness
¥ext-id for
@some-npm-org/quasar-app-extension-awesomeness
is@some-npm-org/awesomeness
这种命名方案的好处之一是,它使得在搜索 Quasar App Extensions 的 npm 包时更容易被发现:应用扩展 - 发现。
¥One of the benefits of this naming scheme is that it makes Quasar App Extensions discoverability easy while searching for their npm packages: App Extension - Discover.
应用扩展结构剖析(Anatomy of App Extensions)
¥Anatomy of App Extensions
应用扩展可以安装、执行和卸载。以下指南以抽象的方式讨论了这一点。有关各个扩展及其使用方法的详细信息,请查阅其各自的存储库。
¥App Extensions can be installed, executed and also uninstalled. The following guide discusses this in an abstract way. For details about individual extensions and how to work with them, please consult their respective repositories.
安装应用扩展(Installing an App Extension)
¥Installing an App Extension
$ quasar ext add <ext-id>
此命令将查找并安装扩展模块。安装完成后,可能会出现一个或多个提示,要求你做出选择或添加扩展程序所需的信息。安装完成后,你将返回到命令行。
¥This command will find and install the extension’s module. After installation is complete, there may be one or more prompts asking you to make choices or add information needed by the extension. When the installation is concluded, you will be returned to the command line.
列出已安装的应用扩展(List Installed App Extensions)
¥List Installed App Extensions
有几种方法可以 “discover” 已安装的应用扩展:
¥There are several ways to “discover” what App Extensions have been installed:
$ quasar ext
$ quasar info
$ cat quasar.extensions.json
“正在运行” 应用扩展(“Running” App Extensions)
¥“Running” App Extensions
运行应用扩展的方法不止一种,因为其中一些可能甚至没有任何可运行的代码(例如,仅仅是复制到项目内特定文件夹的模板文件),而其他一些可能仅仅是安装助手,还有一些可能选择向 Quasar CLI 添加新命令。
¥There is no one way to run app extensions, because some of them might not even have any code to run (i.e. are merely template files copied to specific folders within your project), whereas others may merely be installation helpers and others might choose to add a new command to the Quasar CLI.
不过,每个应用扩展都会在 quasar dev
和 quasar build
期间初始化。
¥Nevertheless, each and every App Extension will be initialized during quasar dev
and quasar build
.
更新应用扩展(Updating an App Extension)
¥Updating an App Extension
你可能需要更新你的扩展程序,更新命令与安装时相同:
¥You may need to update your extension, and this is done with the same command as used for installation:
$ quasar ext add <ext-id>
警告
重新安装扩展可能会覆盖你已更改的文件。你将看到是否覆盖检测到的文件的选项。
¥Reinstalling the extension MIGHT overwrite files that you have changed. You will be presented with the option to overwrite the files detected.
移除应用扩展(Removing an App Extension)
¥Removing an App Extension
你可以通过运行此命令从 Quasar CLI 中移除应用扩展的钩子。不过,根据作者和扩展程序本身的不同,你可能需要手动清理文件。
¥You can remove an App Extension from being hooked from the Quasar CLI by running this command. Depending upon the author and the extension itself, you may have to manually clean up files though.
$ quasar ext remove <ext-id>
官方应用扩展列表(List of official app-extensions)
¥List of official app-extensions
查看 发现应用扩展 页面。
¥Check out Discover App Extensions page.