Vue2.x-03使用vue-cli搭建Vue开发环境

概述

脚手架 vue-cli为咱们省去了手工配置开发环境、运行环境和测试环境的步骤,能够让咱们直接步入 Vue.js 开发,不过咱们须要先搭建下环境,下面开始吧javascript


安装npm

npm(node package manager)node的包管理工具,网上不少教程,这里不赘述了。html

安装成功后,验证以下:
在这里插入图片描述vue


安装vue-cli

使用npm i vue-cli -g将 vue-cli 安装到机器的全局环境java

C:\Users\yangshangwei>npm i vue-cli -g
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
C:\Users\yangshangwei\AppData\Roaming\npm\vue -> C:\Users\yangshangwei\AppData\Roaming\npm\node_modules\vue-cli\bin\vue
C:\Users\yangshangwei\AppData\Roaming\npm\vue-init -> C:\Users\yangshangwei\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-init
C:\Users\yangshangwei\AppData\Roaming\npm\vue-list -> C:\Users\yangshangwei\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-list
+ vue-cli@2.9.6
added 239 packages from 206 contributors in 23.127s

查看vue的版本node

C:\Users\yangshangwei>vue --version
2.9.6

创建工程

这里咱们用的是webpack-simple模板 ,它拥有基础功能的 webpack + vue-loader 用于快速原型开发。webpack

还有一套最经常使用的是webpack,它拥有高级功能的 webpack + vue-loader 用于正式开发:web

vue init webpack-simple vue-todos
C:\Users\yangshangwei>vue init webpack-simple vue-todos

? Project name vue-todos
? Project description A Vue.js project
? Author yangshangwei <yangshangwei@***.com>
? License MIT
? Use sass? No

   vue-cli · Generated "vue-todos".

   To get started:

     cd vue-todos
     npm install
     npm run dev

输入的问题,直接“回车”跳过就好了vue-cli


npm i安装脚手架项目的基本支持包

进入项目目录,npm

C:\Users\yangshangwei>cd vue-todos

安装脚手架项目的基本支持包json

C:\Users\yangshangwei\vue-todos>npm i
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.

> uglifyjs-webpack-plugin@0.4.6 postinstall C:\Users\yangshangwei\vue-todos\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 802 packages from 570 contributors in 39.189s

npm run dev运行由脚手架构建的基本 Vue.js 程序
C:\Users\yangshangwei\vue-todos>npm run dev

> vue-todos@1.0.0 dev C:\Users\yangshangwei\vue-todos
> cross-env NODE_ENV=development webpack-dev-server --open --hot

Project is running at http://localhost:8080/
webpack output is served from /dist/
404s will fallback to /index.html

访问 http://localhost:8080/

在这里插入图片描述


工程结构

咱们导入工程到IDE中,看看 vue-cli 为咱们构造了 一个什么样的代码结构

在这里插入图片描述

相关文章
相关标签/搜索