vue-cli和vue-cli-service有什么区别?

Hri*_*dov 6 vue.js vue-cli

我已经使用Vue一段时间了,但是我刚开始使用CLI,我有点困惑。

我安装了@vue/cli,如果我vue在命令行输入,我将得到:

Usage: vue <command> [options]

Options:
  -V, --version                              output the version number
  -h, --help                                 output usage information

Commands:
  create [options] <app-name>                create a new project powered by vue-cli-service
  add [options] <plugin> [pluginOptions]     install a plugin and invoke its generator in an already created project
  invoke [options] <plugin> [pluginOptions]  invoke the generator of a plugin in an already created project
  inspect [options] [paths...]               inspect the webpack config in a project with vue-cli-service
  serve [options] [entry]                    serve a .js or .vue file in development mode with zero config
  build [options] [entry]                    build a .js or .vue file in production mode with zero config
  ui [options]                               start and open the vue-cli ui
  init [options] <template> <app-name>       generate a project from a remote template (legacy API, requires @vue/cli-init)
  config [options] [value]                   inspect and modify the config
  upgrade [semverLevel]                      upgrade vue cli service / plugins (default semverLevel: minor)
  info                                       print debugging information about your environment

  Run vue <command> --help for detailed usage of given command.
Run Code Online (Sandbox Code Playgroud)

我创建了一个项目,由于某种原因vue我需要安装@vue/cli-service-global,我不记得了。

在那之后,我注意到:

'vue-cli-service' is not recognized as an internal or external command
Run Code Online (Sandbox Code Playgroud)

那是因为我必须安装@vue/cli-service。现在,当我vue-cli-service在命令行中键入时,我得到:

  Usage: vue-cli-service <command> [options]

  Commands:

    serve     start development server
    build     build for production
    inspect   inspect internal webpack config

  run vue-cli-service help [command] for usage of a specific command.
Run Code Online (Sandbox Code Playgroud)

显然,我可以使用这两个CLI工具进行构建,服务和检查。我的问题是-它们之间有什么区别?的自述文件@vue/cli@vue/cli-service指向该页面的链接都只有链接,在该页面上没有给出该问题的答案。

我不能用另一个做什么?我两个都需要吗?

Sty*_*tyx 10

@vue/cli-service-global是一个允许您运行vue servevue build 没有任何本地依赖的软件包。

@vue/cli-service是,实际上做的一个包vue servevue build,双方@vue/cli-service-global@vue/cli依赖于它。

如果您正在使用,@vue/cli则不需要另外安装两个,因为它已经具有@vue/cli-service依赖性。


补充:可以肯定的是,我将进一步解释:

@vue/cli

  1. addcreateconfigui和其它命令
  2. buildserve命令通过@vue/cli-service-global
  3. inspect通过@vue/cli-service包命令(本地依赖项)

@vue/cli-service-global

  1. buildinspect以及serve通过@vue/cli-service软件包发出的命令

@vue/cli-service

  1. buildinspectserve命令

因此,您@vue/cli只需要安装并删除其他两个即可。


补充:关于使用的说明vue-cli-service:使用vue create命令创建项目时,@vue/cli将链接指向已创建项目vue-cli-service内部./node_modules/.bin的二进制文件。

然后,您可以像这样使用它:

  1. 作为vue-cli-service内部npm脚本(package.json)直接访问它:

    "scripts": {
      "watch": "vue-cli-service build --watch"
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 从外壳访问它:./node_modules/.bin/vue-cli-service build --watch。您甚至可以./node_modules/.bin将Shell 添加到您的外壳程序中PATH,然后直接从外壳程序中访问它vue-cli-service