飞道的博客

安装vue环境,并新建Vue项目

469人阅读  评论(0)

一、安装vue环境,并新建Vue项目
首先我们上node.js官网(https://nodejs.org/zh-cn/),下载最新的长期版本,直接运行安装完成之后,

我们就已经具备了node和npm的环境啦。安装完成之后检查下版本信息:

Microsoft Windows [版本 10.0.19041.985]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Administrator>node -v
v14.16.1

C:\Users\Administrator>npm -v
6.14.12

C:\Users\Administrator>

二、安装vue的环境

# 安装淘宝npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
# vue-cli 安装依赖包
cnpm install --g vue-cli

三、进入项目目录,创建一个基于 webpack 模板的新项目: vue init webpack 项目名

PS D:\RuXingDemo\后台管理项目\前端Vue+Element> vue init webpack VueAdmin

? Project name vueadmin
? Project description A Vue.js project
? Author ruxingxing <549589768@qq.com>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recommended) npm

   vue-cli · Generated "VueAdmin".


# Installing project dependencies ...
# ========================

npm WARN deprecated babel-eslint@8.2.6: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated eslint-loader@1.9.0: This loader has been deprecated. Please use eslint-webpack-plugin
npm WARN deprecated extract-text-webpack-plugin@3.0.2: Deprecated. Please use https://github.com/webpack-contrib/mini-css-extract-plugin
npm WARN deprecated html-webpack-plugin@2.30.1: out of support
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and new features!
npm WARN deprecated uglify-es@3.3.9: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

> core-js@2.6.12 postinstall D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> ejs@2.7.4 postinstall D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin\node_modules\ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)


> uglifyjs-webpack-plugin@0.4.6 postinstall D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin\node_modules\webpack\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@~2.3.1 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {
   "os":"darwin","arch":"any"} (current: {
   "os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\watchpack-chokidar2\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {
   "os":"darwin","arch":"any"} (current: {
   "os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\webpack-dev-server\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {
   "os":"darwin","arch":"any"} (current: {
   "os":"win32","arch":"x64"})

added 1394 packages from 716 contributors and audited 1401 packages in 194.275s

49 packages are looking for funding
  run `npm fund` for details

found 51 vulnerabilities (3 low, 42 moderate, 6 high)
  run `npm audit fix` to fix them, or `npm audit` for details


Running eslint --fix to comply with chosen preset rules...
# ========================


> vueadmin@1.0.0 lint D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin
> eslint --ext .js,.vue src "--fix"


# Project initialization finished!
# ========================

To get started:

  cd VueAdmin
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack

四、进入项目:cd VueAdmin

PS D:\RuXingDemo\后台管理项目\前端Vue+Element> cd VueAdmin
PS D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin>

五、npm run dev,启动项目

PS D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin> npm run dev

> vueadmin@1.0.0 dev D:\RuXingDemo\后台管理项目\前端Vue+Element\VueAdmin
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

 10% 12% 12% 12% 12% 13% 13% building modules 29/31 modules 2 active ...项目\前端Vue+Element\VueAdmin\src\App.vue{
    parser: "babylon" } is deprecated; we now treat it as {
    parser: "babel" }.
 14% 14% 95% emitting

 DONE  Compiled successfully in 4057ms                                                                      上午11:28:14

 I  Your application is running here: http://localhost:8080


六、vue项目目录

1、build:构建脚本目录

1)build.js ==> 生产环境构建脚本;

2)check-versions.js ==> 检查npm,node.js版本;

3)utils.js ==> 构建相关工具方法;

4)vue-loader.conf.js ==> 配置了css加载器以及编译css之后自动添加前缀;

5)webpack.base.conf.js ==> webpack基本配置;

6)webpack.dev.conf.js ==> webpack开发环境配置;

7)webpack.prod.conf.js ==> webpack生产环境配置;

2、config:项目配置

1)dev.env.js ==> 开发环境变量;

2)index.js ==> 项目配置文件;

3)prod.env.js ==> 生产环境变量;

3、node_modules:npm 加载的项目依赖模块

4、src:这里是我们要开发的目录,基本上要做的事情都在这个目录里。里面包含了几个目录及文件:

1)assets:资源目录,放置一些图片或者公共js、公共css。这里的资源会被webpack构建;

2)components:组件目录,我们写的组件就放在这个目录里面;

3)router:前端路由,我们需要配置的路由路径写在index.js里面;

4)App.vue:根组件;

5)main.js:入口js文件;

5、static:静态资源目录,如图片、字体等。不会被webpack构建

6、index.html:首页入口文件,可以添加一些 meta 信息等

7、package.json:npm包配置文件,定义了项目的npm脚本,依赖包等信息

8、README.md:项目的说明文档,markdown 格式

9、.xxxx文件:这些是一些配置文件,包括语法配置,git配置等


转载:https://blog.csdn.net/OnlyRu/article/details/117020817
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场