首页 > 解决方案 > 为什么 vue-cli 有两个 vuejs 启动命令?

问题描述

我在网上查找并遇到了两个不同的运行命令,其奇怪的原因是例如 React 有 command create-react-app <name of app>,但是对于 vue-cli 我找到了这两个命令vue create <name of app>vue init webpack <name of app>.

我在运行这两个命令后仔细检查,发现它们都包含 webpack,但结构不同。第一个预装了 vuex,而另一个则没有。第二个命令虽然有很多额外的 devDependencies。

对于包含 vue-router 和 vuex 的多页 vuejs 应用程序,我只是有点困惑哪个命令是正确的。

标签: webpackvuejs2vuexvue-routervue-cli-3

解决方案


对于 Vue CLI v3,您可以使用vue createvue ui引导应用程序。对于 Vue CLI v2,您使用vue init.

如果你安装了 Vue CLI v3,你仍然可以使用vue init,尽管它被认为是一个遗留 API:

$ vue --version
3.0.0

$ vue init

  Usage: init [options] <template> <app-name>

  generate a project from a remote template (legacy API, requires @vue/cli-init)

  Options:

    -c, --clone  Use git clone when fetching remote template
    --offline    Use cached template
    -h, --help   output usage information

$ vue create

  Usage: create [options] <app-name>

  create a new project powered by vue-cli-service

  Options:

    -p, --preset <presetName>       Skip prompts and use saved or remote preset
    -d, --default                   Skip prompts and use default preset
    -i, --inlinePreset <json>       Skip prompts and use inline JSON string as preset
    -m, --packageManager <command>  Use specified npm client when installing dependencies
    -r, --registry <url>            Use specified npm registry when installing dependencies (only for npm)
    -g, --git [message]             Force git initialization with initial commit message
    -n, --no-git                    Skip git initialization
    -f, --force                     Overwrite target directory if it exists
    -c, --clone                     Use git clone when fetching remote preset
    -x, --proxy                     Use specified proxy when creating project
    -b, --bare                      Scaffold project without beginner instructions
    -h, --help                      output usage information

Vue CLI 在版本 3 上是稳定的,所以我会确保你已经安装了它,并使用vue create命令或vue ui命令。它vue ui仍处于测试阶段,我还没有尝试过,但它看起来不错。您可以通过 CLI 网站了解更多信息:https ://cli.vuejs.org/ 。


推荐阅读