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

时间:2019-01-18 06:22:06

标签: 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.

我用vue创建了一个项目,出于某种原因,我需要安装@vue/cli-service-global

但是,在那之后,我注意到了:

'vue-cli-service' is not recognized as an internal or external command

那是因为我必须安装@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.

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

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

1 个答案:

答案 0 :(得分:8)

@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. 通过build软件包的
  3. serve@vue/cli-service-global命令
  4. 通过inspect软件包的
  5. @vue/cli-service命令(本地依赖项)

@vue/cli-service-global

    通过build软件包的
  1. inspectserve@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"
    }
    
  2. 从外壳程序./node_modules/.bin/vue-cli-service build --watch中访问它。 您甚至可以将./node_modules/.bin添加到外壳PATH中,并直接以vue-cli-service的身份从外壳中访问它。