请熟悉 Quasar 项目中可用命令的列表:
$ quasar -h
Running @quasar/cli v<...>
Running @quasar/app-vite v<...>
Example usage
$ quasar <command> <options>
Help for a command
$ quasar <command> --help
$ quasar <command> -h
Options
--no-color Disable colored output (can be used with any command)
--version, -v Print Quasar App CLI version
Commands
dev, d Start a dev server for your App
build, b Build your app for production
prepare, p Prepare the app for linting, type-checking, IDE integration, etc.
clean, c Clean dev/build cache, /dist folder & entry points
new, n Quickly scaffold page/layout/component/... vue file
mode, m Add/remove Quasar Modes for your App
inspect Inspect Vite/Rolldown configs used under the hood
- keeps into account your quasar.config file
and your installed App Extensions
ext, e Manage Quasar App Extensions
run, r Run specific command provided by an installed
Quasar App Extension
describe Describe a Quasar API (component)
info, i Display info about your machine and your App
help, h Displays this message
If the specified command is not found, then "quasar run"
will be executed with the provided arguments.
Commands supplied by @quasar/cli global installation:
upgrade Check (and optionally) upgrade Quasar packages
from a Quasar project folder
serve Create an ad-hoc server on App's distributables查看某个命令的帮助信息:
quasar [command name] --helpUpgrade
用于从 Quasar 项目目录中升级 Quasar 包的辅助命令:
$ quasar upgrade -h
Description
将所有 Quasar 包升级到与当前使用的 API 兼容的最新版本
(除非使用了 -m/--major 参数,可能包含破坏性变更)。
仅在项目目录中有效,将所有 Quasar 相关包升级到最新的次版本
(或选择升级到最新的主版本)。
同时也会升级官方的 Quasar App Extensions。
Usage
# 会提示你是否安装
$ quasar upgrade
# 同时检查预发布版本(alpha/beta/rc):
$ quasar upgrade -p
# 检查 major 版本的更新(包括破坏性变更):
$ quasar upgrade -m
# 跳过安装提示直接执行,
# 可与上述任意参数组合,加上 "-i"(或 "--install"):
$ quasar upgrade -i
Options
--install, -i 跳过安装提示直接执行
--prerelease, -p 允许预发布版本(alpha/beta/rc)
--major, -m 允许更新的主版本(破坏性变更)
--registry, -r NPM 源 URL
* 默认使用机器上 npm 配置的源
* 示例:https://registry.npmjs.org/
--no-color 禁用彩色输出
--help, -h 显示此帮助信息使用编辑器自带终端时的注意事项
如果您在使用一个编辑器内置的终端运行 quasar upgrade 命令并得到报错: Command not found 或 @quasar/cli version appears to be undefined 时。您需要检查编辑器终端的相关设置: 取消勾选 Add ‘node_modules/.bin’ from the project root to %PATH% 然后重启编辑器。
Info
Quasar CLI 配备了多个 NPM 包(Vite,Vue 等)的稳定组合,这些软件包在经过大量测试后会频繁更新。
有时为了定位问题,需要查看您的项目中各个包的版本,请在项目根目录中运行 quasar info 命令。
Dev
$ quasar dev -h
Description
以开发模式启动应用(热代码重载、错误报告等)
Usage
$ quasar dev
$ quasar dev -p <port number>
$ quasar dev -m ssr
# "quasar dev -m capacitor -T ios" 的别名
$ quasar dev -m ios
# "quasar dev -m capacitor -T android" 的别名
$ quasar dev -m android
# 传递额外的参数和/或选项给
# 底层的 "cordova" 或 "electron" 可执行文件:
$ quasar dev -m cordova -T ios -- some params --and options --here
$ quasar dev -m electron -- --no-sandbox --disable-setuid-sandbox
# 在 Windows 上使用 Powershell 时:
$ quasar dev -m cordova -T ios '--' some params --and options --here
$ quasar dev -m electron '--' --no-sandbox --disable-setuid-sandbox
Options
--mode, -m 应用模式 [spa|ssr|pwa|cordova|capacitor|electron|bex](默认:spa)
--port, -p 应用启动的端口号
--hostname, -H 用于提供应用服务的主机名
--devtools, -d 打开远程 Vue Devtools
--no-color 禁用彩色输出
--help, -h 显示此帮助信息
仅适用于 Capacitor 和 Cordova 模式:
--target, -T (必填)应用目标平台 [android|ios]
--ide, -i (仅生产)打开 IDE 构建应用而非使用 CLI 工具
仅适用于 BEX 模式:
--target, -T 浏览器目标 [chrome|firefox]
(默认:chrome)Quasar 开发服务器允许您通过编译和维护内存中的代码来开发应用程序。web 服务器将为您的应用程序提供服务,同时提供开箱即用的热重新加载。在内存中运行可以在更改代码时更快地重建。
热重新加载不仅仅是在代码更改时刷新浏览器。它跳过刷新并动态更新代码,同时保持应用程序的状态(如 Vue 的 model 数据)。请注意,在某些特殊情况下,这是不可能的,因此 dev Web 服务器将会刷新您的浏览器。(始终确保一次只运行一个 Quasar CLI 实例,否则热重新服务和其他服务将中断)
根据您想要开发的内容,您可以使用 quasar dev 命令启动开发服务器,如下所示:
$ quasar dev -h
Description
以开发模式启动应用(HMR、错误报告等)
Usage
$ quasar dev
$ quasar dev -p <port number>
$ quasar dev -m ssr
# "quasar dev -m capacitor -T ios" 的别名
$ quasar dev -m ios
# "quasar dev -m capacitor -T android" 的别名
$ quasar dev -m android
# 传递额外的参数和/或选项给
# 底层的 "cordova" 或 "electron" 可执行文件:
$ quasar dev -m cordova -T ios -- some params --and options --here
$ quasar dev -m electron -- --no-sandbox --disable-setuid-sandbox
# 在 Windows 上使用 Powershell 时:
$ quasar dev -m cordova -T ios '--' some params --and options --here
$ quasar dev -m electron '--' --no-sandbox --disable-setuid-sandbox
Options
--mode, -m 应用模式 [spa|ssr|pwa|cordova|capacitor|electron|bex](默认:spa)
--port, -p 应用启动的端口号
--hostname, -H 用于提供应用服务的主机名
--target, -T 应用目标平台
- Capacitor & Cordova: [android|ios]
- Bex: [chrome|firefox]
--devtools, -d 打开远程 Vue Devtools
--no-color 禁用彩色输出
--help, -h 显示此帮助信息
仅适用于 Capacitor 和 Cordova 模式:
--ide, -i (仅生产)打开 IDE 构建应用而非使用 CLI 工具如果要更改应用程序的主机名或端口,有 3 种方式:
- 编辑
/quasar.config文件:devServer: { host: '...', port: ... }content_paste - 在命令中传入 ‘-H’ (hostname) 和 ‘-p’ (port) 选项。
- 如果只是一次性配置,还可以通过环境变量来修改:
PORT=3000 quasar dev HOSTNAME=1.1.1.14 quasar devcontent_paste
如果热重新加载似乎有问题,可以尝试两种修复方法:
使用更改项目文件夹的权限
sudo chown -R username: .content_paste或使用 root 权限运行 dev 服务器
sudo quasar devcontent_paste
Build
$ quasar build -h
Description
Builds distributables of your app.
Usage
$ quasar build
$ quasar build -m ssr
$ quasar build -m capacitor -T ios
# passing extra parameters and/or options to
# underlying "cordova" executable:
$ quasar build -m electron -- some params --and options --here
# when on Windows and using Powershell:
$ quasar build -m electron '--' some params --and options --here
Options
--mode, -m App mode [spa|ssr|pwa|cordova|capacitor|electron|bex] (default: spa)
--target, -T App target
- Cordova (default: all installed)
[android|ios]
- Capacitor
[android|ios]
- Electron with default "@electron/packager" bundler (default: yours)
[darwin|win32|linux|mas|all]
- Electron with "electron-builder" bundler (default: yours)
[darwin|mac|win32|win|linux|all]
- Bex
[chrome|firefox]
--publish, -P Also trigger publishing hooks (if any are specified)
- Has special meaning when building with Electron mode and using
electron-builder as bundler
--debug, -d Build for debugging purposes
--skip-pkg, -s Build only UI (skips creating Cordova/Capacitor/Electron executables or BEX zip file)
- Cordova (it only fills in /src-cordova/www folder with the UI code)
- Capacitor (it only fills in /src-capacitor/www folder with the UI code)
- Electron (it only creates the /dist/electron/UnPackaged folder)
- BEX (it only creates the /dist/bex-* folder)
--no-summary Don't output build summary at the end of the process
--no-color Disable colored output
--help, -h Displays this message
ONLY for Cordova and Capacitor mode:
--ide, -i Open IDE (Android Studio / XCode) instead of finalizing with a
terminal/console-only build
ONLY for Electron mode:
--bundler, -b Bundler (@electron/packager or electron-builder)
[packager|builder]
--arch, -A App architecture (default: yours)
- with default "@electron/packager" bundler:
[ia32|x64|armv7l|arm64|mips64el|all]
- with "electron-builder" bundler:
[ia32|x64|armv7l|arm64|all]
ONLY for electron-builder (when using "publish" parameter):
--publish, -P Publish options [onTag|onTagOrDraft|always|never]
- see https://www.electron.build/configuration/publishQuasar CLI 可以将所有内容打包在一起,并优化您的应用程序构建生产环境下的代码。它会利用压缩代码,提取三方组件,利用浏览器缓存等手段进行优化。
# 构建一个 SPA 用于生产环境
quasar build
# ...or
quasar build -m spa
# 构建一个 SSR 用于生产环境
quasar build -m ssr
# 构建一个 PWA 用于生产环境
quasar build -m pwa
# 构建一个 BEX 用于生产环境
quasar build -m bex -T [chrome|firefox]
# 构建一个手机应用,用于生产环境 (通过 Capacitor)
quasar build -m capacitor -T [android|ios]
# 或者更短的格式:
quasar build -m [android|ios]
# 构建一个 electron 桌面应用,用于生产环境
quasar build -m electron
# 传递更多的参数和选项给底层的 "cordova"
quasar build -m cordova -T ios -- some params --and options --here
# 当在 Windows 上使用 Powershell 时:
quasar build -m cordova -T ios '--' some params --and options --here
# 构建一个可调试的版本
# (带有 source-maps 并且不会压缩代码)
quasar build -d [-m <mode>]Prepare
为 IDE 准备项目文件夹,使自动补全和其他 IDE 功能正常工作。
quasar prepare
# silent (no terminal output)
quasar prepare --silent
quasar prepare -sClean
清除所有构建产物:
quasar clean
# 之后需要重新运行 "quasar prepare"New
生成 Components, Pages, Layouts, Pinia Store。
TIP
这个命令只是一个辅助,用于快速创建一个页面/布局/组件/Pinia store 的模板文件。您可以不需要使用它,但当您不知道如何开始时可以帮助您。
$ quasar new -h
Description
Quickly scaffold files.
Usage
$ quasar new <p|page> [-f <js|ts>] <page_file_name>
$ quasar new <l|layout> [-f <js|ts>] <layout_file_name>
$ quasar new <c|component> [-f <js|ts>] <component_file_name>
$ quasar new <b|boot> [-f <js|ts>] <boot_name>
$ quasar new <s|store> [-f <js|ts>] <store_module_name>
$ quasar new ssrmiddleware [-f <js|ts>] <middleware_name>
Examples
# Create src/pages/MyNewPage.vue:
$ quasar new p MyNewPage
# Create src/pages/MyNewPage.vue and src/pages/OtherPage.vue:
$ quasar new p MyNewPage OtherPage
# Create src/layouts/shop/Checkout.vue
$ quasar new layout shop/Checkout.vue
# Create src/layouts/shop/Checkout.vue (forcing TypeScript)
$ quasar new layout -f ts shop/Checkout.vue
# Create a store with TypeScript (-f ts is optional if tsconfig.json is present)
$ quasar new store -f ts myStore
Options
--no-color Disable colored output
--help, -h Displays this message
--format -f <option> (optional) Use a supported format for the template.
This gets inferred automatically for your project.
Possible overriding values:
* js - JS template
* ts - TS templateMode
$ quasar mode -h
Description
Add/Remove support for PWA / BEX / Cordova / Capacitor / Electron modes.
Usage
$ quasar mode [add|remove] [pwa|ssr|bex|cordova|capacitor|electron] [--yes]
# determine what modes are currently installed:
$ quasar mode
Options
--yes, -y Skips the "Are you sure?" question
when removing a Quasar mode
--no-color Disable colored output
--help, -h Displays this message只有当您的项目是使用 Quasar CLI 创建的时,您才能构建 SPA (单页面应用), SSR (服务端渲染应用), PWA (渐进式 Web 应用), 手机 App (通过 Cordova), 或/和 Electron 应用。当您开发时,您可以直接运行 “quasar dev” 或 “quasar build”,相关的模式会被自动安装。
添加开发模式会在项目的根目录下添加一个 “src-*” 目录,其中是被添加模式的专属源代码:
| 目录 | Mode | 描述 |
|---|---|---|
| src-ssr | ssr | 包括生产环境下的 Node 服务代码。 |
| src-pwa | pwa | 包括 Service Worker 文件供您调整。 |
| src-cordova | cordova | 其中是一个 Cordova 项目,它会使用 src 目录下的代码作为视图内容。调整您的 Cordova 配置,可以添加/删除平台、启动画面、Cordova 插件等。不要修改 “src-cordova/www” 目录下的文件,因为它们是使用 src 下的文件构建出来的,每次构建都会被重新覆盖。 |
| src-electron | electron | 包括 Electron 主进程的代码,渲染进程会采用 src 目录下的代码。 |
| src-bex | bex | 包括适用于开发浏览器插件的专属文件。 |
如果您发现您不需要某个开发模式时,您可以删除它,这将永久删除相应的 “src-*” 文件夹。
quasar mode remove pwaDescribe
这个命令可以查看您项目中使用的任意一个 Quasar 组件/指令/插件的 API。 它查询的是您项目中安装的特定的 Quasar 版本
例如: quasar describe QIcon, quasar describe TouchPan, quasar describe Cookies.
$ quasar describe -h
Description
Describes a component API for project's Quasar version being used
Usage
$ quasar describe <component/directive/Quasar plugin>
# list all available API entries:
$ quasar describe list
# list available API entries that contain a String (ex "storage"):
$ quasar describe list storage
# display everything:
$ quasar describe QIcon
# displaying only props:
$ quasar describe QIcon -p
# displaying props and methods only:
$ quasar describe QIcon -p -m
# filtering by "si":
$ quasar describe QIcon -f si
# filtering only props by "co":
$ quasar describe QIcon -p -f co
# Open docs URL:
$ quasar describe QIcon -d
Options
--filter, -f <filter> Filters the API
--props, -p Displays the API props
--slots, -s Displays the API slots
--events, -e Displays the API events
--methods, -m Displays the API methods
--computedProps, -c Displays the API computed props
--value, -v Displays the API value
--arg, -a Displays the API arg
--modifiers, -M Displays the API modifiers
--injection, -i Displays the API injection
--quasar, -q Displays the API quasar conf options
--docs, -d Opens the docs API URL
--no-color Disable colored output
--help, -h Displays this message$ quasar describe QIcon
Describing QIcon component API
Description is based on your project's Quasar version
Properties
name (String)
Description: Name of the icon, following Quasar convention
Examples:
map
ion-add
color (String)
Description: Color name for component from the Quasar Color Palette
Examples:
primary
teal-10
size (String)
Description: Size in CSS units, including unit name
Examples:
16px
2rem
left (Boolean)
Description: Apply a standard margin on the left side. Useful if icon is on the right side of something.
right (Boolean)
Description: Apply a standard margin on the right side. Useful if icon is on the left side of something.
Slots
default
Suggestions: QTooltip or QMenu
Scoped Slots
*No scoped slots*
Events
*No events*
Methods
*No methods*Inspect
这个命令用于查看 Quasar CLI 生成的 Vite 配置。
$ quasar inspect -h
Description
Inspect Quasar generated Vite config
Usage
$ quasar inspect
$ quasar inspect -c build
$ quasar inspect -m electron -p 'build.outDir'
Options
--cmd, -c Quasar command [dev|build] (default: dev)
--mode, -m App mode [spa|ssr|pwa|bex|cordova|capacitor|electron] (default: spa)
--depth, -d Number of levels deep (default: 2)
--path, -p Path of config in dot notation
Examples:
-p module.rules
-p plugins
--thread, -t Display only one specific app mode config thread
--no-color Disable colored output
--help, -h Displays this messageExt
这个命令用于管理 App 扩展.
$ quasar ext -h
Description
Manage Quasar App Extensions
Usage
# display list of installed extensions
$ quasar ext
# Add Quasar App Extension
$ quasar ext add <ext-id>
# Remove Quasar App Extension
$ quasar ext remove <ext-id>
# Add Quasar App Extension, but
# skip installing the npm package
# (assumes it's already installed)
$ quasar ext invoke <ext-id>
# Remove Quasar App Extension, but
# skip uninstalling the npm package
$ quasar ext uninvoke <ext-id>
Options
--no-color Disable colored output
--help, -h Displays this messageRun
这个命令用于运行某个 App 扩展中的命令
$ quasar run -h
Description
Run app extension provided commands
Usage
$ quasar run <extension-id> <cmd> [args, params]
$ quasar <extension-id> <cmd> [args, params]
$ quasar run iconify create pic -s --mark some_file
$ quasar iconify create pic -s --mark some_file
# Note: "iconify" is an example and not a real extension.
# Looks for installed extension called "iconify"
# (quasar-app-extension-iconify extension package)
# and runs its custom defined "create" command
# with "pic" argument and "-s --mark some_file" params
Options
--no-color Disable colored output
--help, -h Displays this messageServe
这个命令也可以在生产环境中使用,它由全局安装的 @quasar/cli 包提供。
$ quasar serve -h
Description
Start a HTTP(S) server on a folder.
Usage
$ quasar serve [path]
$ quasar serve . # serve current folder
If you serve a SSR dist folder built with Quasar CLI then
run "node index.js" instead.
Options
--port, -p Port to use (default: 4000)
--hostname, -H Address to use (default: 0.0.0.0)
--silent, -s Suppress log message
--cors Enable CORS
--open, -o Open browser window after starting
--index, -i <path> Index url path (default: index.html)
--history Use history mode;
All requests fallback to /index.html,
or whatever "--index" parameter specifies
(default: false)
--https Enable HTTPS
--cert, -C [path] Path to SSL cert file (Optional)
--key, -K [path] Path to SSL key file (Optional)
--no-color Disable colored output
--help, -h Displays this message
--proxy, -P [path] Path to proxy definition file (Optional)
Proxy file example:
// https://hono.dev/docs/helpers/proxy
// "proxy" param is hono/proxy
export default ({ app, proxy }) => {
app.get('/proxy/:path', (c) => {
return proxy('http://some.api.com/' + c.req.param('path'))
})
}自定义 Node server
当构建一个 SPA 或 PWA 时,产物目录可以使用任意的静态服务器提供服务。为了测试它(假设您没有特定的 publicPath 或者没有使用 Vue 路由的 “history” 模式),您可以使用 “http-server” npm 包。
或者您可以建立您自己的服务器。 这里有些例子:
// 当使用默认的 Vue Router "hash" 路由模式时
import express from 'express'
import serveStatic from 'serve-static'
const port = process.env.PORT || 5000
const app = express()
app.use(serveStatic(...path-to-dist...))
app.listen(port)// 当使用 Vue Router "history" 路由模式时
import express from 'express'
import serveStatic from 'serve-static'
import history from 'connect-history-api-fallback'
const port = process.env.PORT || 5000
const app = express()
app.use(history())
app.use(serveStatic(...path-to-dist...))
app.listen(port)如果您需要重写 API 的 URL,或者需要代理您的 API 请求,那么您可以使用 “http-proxy-middleware” 软件包:
// 在前面的两个例子中加上这一点:
import { createProxyMiddleware } from "http-proxy-middleware";
// ...
app.use(
"/api",
createProxyMiddleware({
target: `http://my-api.com:5050`,
pathRewrite: { "^/api": "" },
}),
);
// then app.listen(...)最后,运行文件:
node my-server.js