为什么捐赠
API 浏览器
联系站长
Quasar CLI with Vite - @quasar/app-vite
命令列表

请熟悉 Quasar 项目中可用命令的列表:

$ quasar -h

  Example usage
    $ quasar <command> <options>

  Help for a command
    $ quasar <command> --help
    $ quasar <command> -h

  Options
    --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/esbuild 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] --help

Upgrade

需要在 quasar 项目目录中运行,检查当前项目可更新的 Quasar 包。

# 查看所有选项:
$ quasar upgrade -h

# 检查没有破坏性更新的包并展示
# 但是不会自动安装
$ quasar upgrade

# 检查预发布版本的更新:
$ quasar upgrade -p

# 检查 major 版本的更新(包括破坏性的更新)
$ quasar upgrade -m

# 使用指定的 npm 源
# (@quasar/cli v2.4+ 支持)
$ quasar upgrade -r https://registry.npmjs.org/

# 执行更新
# 可同时使用上述参数来指定更新何种版本
$ quasar upgrade -i

使用编辑器自带终端时的注意事项

如果您在使用一个编辑器内置的终端运行 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
    Starts the app in development mode (hot-code reloading, error
    reporting, etc)

  Usage
    $ quasar dev
    $ quasar dev -p <port number>

    $ quasar dev -m ssr

    # alias for "quasar dev -m capacitor -T ios"
    $ quasar dev -m ios

    # alias for "quasar dev -m capacitor -T android"
    $ quasar dev -m android

    # passing extra parameters and/or options to
    # underlying "cordova" or "electron" executables:
    $ quasar dev -m cordova -T ios -- some params --and options --here
    $ quasar dev -m electron -- --no-sandbox --disable-setuid-sandbox
    # when on Windows and using Powershell:
    $ quasar dev -m cordova -T ios '--' some params --and options --here
    $ quasar dev -m electron '--' --no-sandbox --disable-setuid-sandbox

  Options
    --mode, -m       App mode [spa|ssr|pwa|cordova|capacitor|electron|bex] (default: spa)
    --port, -p       A port number on which to start the application
    --hostname, -H   A hostname to use for serving the application
    --devtools, -d   Open remote Vue Devtools
    --help, -h       Displays this message

    Only for Cordova mode:
    --target, -T     (required) App target [android|ios]
    --emulator, -e   (optional) Emulator name
                        Examples: iPhone-7, iPhone-X
                        iPhone-X,com.apple.CoreSimulator.SimRuntime.iOS-12-2
    --ide, -i        Open IDE (Android Studio / XCode) instead of letting Cordova
                       boot up the emulator / building in terminal, in which case
                       the "--emulator" param will have no effect


    Only for Capacitor mode:
    --target, -T     (required) App target [android|ios]

    Only for BEX mode:
    --target, -T     (required) Browser family target [chrome|firefox]

Quasar 开发服务器允许您通过编译和维护内存中的代码来开发应用程序。web 服务器将为您的应用程序提供服务,同时提供开箱即用的热重新加载。在内存中运行可以在更改代码时更快地重建。

热重新加载不仅仅是在代码更改时刷新浏览器。它跳过刷新并动态更新代码,同时保持应用程序的状态(如 Vue 的 model 数据)。请注意,在某些特殊情况下,这是不可能的,因此 dev Web 服务器将会刷新您的浏览器。(始终确保一次只运行一个 Quasar CLI 实例,否则热重新服务和其他服务将中断)

根据您想要开发的内容,您可以使用 quasar dev 命令启动开发服务器,如下所示:

# 开发一个 SPA
$ quasar dev
# ...或者
$ quasar dev -m spa

# 开发一个 SSR
$ quasar dev -m ssr

# 开发一个 PWA
$ quasar dev -m pwa

# 开发一个 BEX 浏览器插件
$ quasar dev -m bex

# 开发一个手机应用 (通过 Cordova)
$ quasar dev -m cordova -T [android|ios]
# 或者更短的格式:
$ quasar dev -m [android|ios]

# 开发一个 Electron App
$ quasar dev -m electron

# 开发一个浏览器扩展 (BEX)
$ quasar dev -m bex -T [chrome|firefox]

# 传递更多的参数和选项给底层的 "cordova" 或 "electron"
$ quasar dev -m ios -- some params --and options --here
$ quasar dev -m electron -- --no-sandbox --disable-setuid-sandbox
# 当在 Windows 上使用 Powershell 时:
$ quasar dev -m ios '--' some params --and options --here
$ quasar dev -m electron '--' --no-sandbox --disable-setuid-sandbox

如果要更改应用程序的主机名或端口,有 3 种方式:

  • 编辑 /quasar.config 文件:
    devServer: {
      host: '...',
      port: ...
    }
  • 在命令中传入 ‘-H’ (hostname) 和 ‘-p’ (port) 选项。
  • 如果只是一次性配置,还可以通过环境变量来修改:
    $ PORT=3000 quasar dev
    $ HOSTNAME=1.1.1.14 quasar dev

如果热重新加载似乎有问题,可以尝试两种修复方法:

  • 使用更改项目文件夹的权限

    sudo chown -R username: .
  • 或使用 root 权限运行 dev 服务器

    sudo quasar dev

Build

$ quasar build -h

  Description
    Builds distributables of your app.

  Usage
    $ quasar build
    $ quasar build -p <port number>

    $ quasar build -m ssr

    # alias for "quasar build -m cordova -T ios"
    $ quasar build -m ios

    # alias for "quasar build -m cordova -T android"
    $ quasar build -m android

    # passing extra parameters and/or options to
    # underlying "cordova" executable:
    $ quasar build -m ios -- some params --and options --here
    # when on Windows and using Powershell:
    $ quasar build -m ios '--' 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)
                      - 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)
    --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/publish

    Only for BEX mode:
    --target, -T     (required) Browser family target [chrome|firefox]

Quasar 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]

# 构建一个手机应用,用于生产环境 (通过 Cordova)
$ quasar build -m cordova -T [android|ios]
# 或者更短的格式:
$ quasar build -m [android|ios]

# 构建一个 electron 桌面应用,用于生产环境
$ quasar build -m electron

# 传递更多的参数和选项给底层的 "cordova"
$ quasar build -m ios -- some params --and options --here
# 当在 Windows 上使用 Powershell 时:
$ quasar build -m ios '--' some params --and options --here

# 构建一个可调试的版本
# (带有 source-maps 并且不会压缩代码)
$ quasar build -d [-m <mode>]

Prepare

为 IDE 准备项目文件夹,使自动补全和其他 IDE 功能正常工作。

$ quasar prepare

Clean

清除所有构建产物:

$ 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
    --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 template

Mode

$ 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
    --help, -h    Displays this message

只有当您的项目是使用 Quasar CLI 创建的时,您才能构建 SPA (单页面应用), SSR (服务端渲染应用), PWA (渐进式 Web 应用), 手机 App (通过 Cordova), 或/和 Electron 应用。当您开发时,您可以直接运行 “quasar dev” 或 “quasar build”,相关的模式会被自动安装。

添加开发模式会在项目的根目录下添加一个 “src-*” 目录,其中是被添加模式的专属源代码:

目录Mode描述
src-ssrssr包括生产环境下的 Node 服务代码。
src-pwapwa包括 Service Worker 文件供您调整。
src-cordovacordova其中是一个 Cordova 项目,它会使用 src 目录下的代码作为视图内容。调整您的 Cordova 配置,可以添加/删除平台、启动画面、Cordova 插件等。不要修改 “src-cordova/www” 目录下的文件,因为它们是使用 src 下的文件构建出来的,每次构建都会被重新覆盖。
src-electronelectron包括 Electron 主进程的代码,渲染进程会采用 src 目录下的代码。
src-bexbex包括适用于开发浏览器插件的专属文件。

如果您发现您不需要某个开发模式时,您可以删除它,这将永久删除相应的 “src-*” 文件夹。

$ quasar mode remove pwa

Describe

这个命令可以查看您项目中使用的任意一个 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
    --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
    --help, -h       Displays this message

Ext

这个命令用于管理 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
    --help, -h       Displays this message

Run

这个命令用于运行某个 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
    --help, -h       Displays this message

Serve

这个命令也可以在生产环境中使用,它由全局安装的 @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 folder built with the CLI then
    control is yielded to /index.js and params have no effect.

  Options
    --port, -p              Port to use (default: 4000)
    --hostname, -H          Address to use (default: 0.0.0.0)
    --gzip, -g              Compress content (default: true)
    --silent, -s            Suppress log message
    --colors                Log messages with colors (default: true)
    --open, -o              Open browser window after starting
    --cache, -c <number>    Cache time (max-age) in seconds;
                            Does not apply to /service-worker.js
                            (default: 86400 - 24 hours)
    --micro, -m <seconds>   Use micro-cache (default: 1 second)

    --history               Use history api fallback;
                              All requests fallback to /index.html,
                              unless using "--index" parameter
    --index, -i <file>      History mode (only!) index url path
                              (default: index.html)

    --https                 Enable HTTPS
    --cert, -C [path]       Path to SSL cert file (Optional)
    --key, -K [path]        Path to SSL key file (Optional)
    --proxy <file.mjs>      Proxy specific requests defined in file;
                            File must export Array ({ path, rule })
                            See example below. "rule" is defined at:
                            https://github.com/chimurai/http-proxy-middleware
    --cors                  Enable CORS for all requests
    --help, -h              Displays this message

  Proxy file example
    export default [
      {
        path: '/api',
        rule: { target: 'http://www.example.org' }
      }
    ]
    --> will be transformed into app.use(path, httpProxyMiddleware(rule))

自定义 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