我已经使用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的链接,其中没有对该问题的答案。
我对另一个不能做什么?我需要两个吗?
答案 0 :(得分:8)
@vue/cli-service-global
是一个软件包,允许您运行vue serve
和vue build
而没有任何本地依赖项。
@vue/cli-service
是一个实际上由vue serve
和vue build
组成的@vue/cli-service-global
和@vue/cli
的软件包。
如果您使用的是@vue/cli
,则不需要另外安装两个,因为它的依赖项中已经包含@vue/cli-service
。
已添加:为了确定,我将对其进行详细说明:
@vue/cli
:
add
,create
,config
,ui
和其他命令build
软件包的serve
和@vue/cli-service-global
命令inspect
软件包的@vue/cli-service
命令(本地依赖项) @vue/cli-service-global
:
build
软件包的inspect
,serve
和@vue/cli-service
命令 @vue/cli-service
:
build
,inspect
和serve
命令因此,您只需要安装@vue/cli
并删除其他两个。
已添加:对使用vue-cli-service
的说明:
使用vue create
命令创建项目时,@vue/cli
会链接到已创建项目的vue-cli-service
中的./node_modules/.bin
二进制文件。
然后您可以像这样使用它:
在vue-cli-service
脚本(npm
)中以package.json
的形式直接访问它:
"scripts": {
"watch": "vue-cli-service build --watch"
}
./node_modules/.bin/vue-cli-service build --watch
中访问它。
您甚至可以将./node_modules/.bin
添加到外壳PATH
中,并直接以vue-cli-service
的身份从外壳中访问它。