码迷,mamicode.com
首页 > 其他好文 > 详细

第一个Vue页面

时间:2020-07-29 18:01:10      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:star   erro   shell   reset   code   项目   demo   sel   runtime   

一、安装node

https://nodejs.org/en/ 直接选择LTS长期支持版下载对应系统安装文件进行安装。
安装完后,打开cmd命令行界面

node -v

查看对应安装版本,例:v12.18.3
安装淘宝cnpm

sudo npm install cnpm -g --registry=https://registry.npm.taobao.org

安装yarn(fackbook依赖管理工具与Npm功能一样,推荐使用!!!)

npm install -g yarn

通过yarn -v查看安装版本
Yarn 淘宝源安装

yarn config set registry https://registry.npm.taobao.org -g

二、全局安装Vue-cli脚手架

sudo cnpm install vue-cli -g

可通过vue --version查看vue-cli版本号

三、全局安装Webpack打包

sudo cnpm install webpack -g

同样可通过webpack -v查看版本

四、安装http服务

安装npm serve

sudo npm install -g serve

安装 http-server

npm install http-server -g 

五、使用Vue-cli脚手架搭建一个vue页面

<!--- 初始化项目 -->
vue init webpack demo001
Project name demo001
Project description A Vue.js project
Author swift <aswift@126.com>
<!--- vue打包方式 -->
Vue build standalone
<!--- 是否安装vue路由 -->
Install vue-router? Yes
<!--- 是否启动ESLint代码检测 -->
Use ESLint to lint your code? No
<!--- 是否设置单元测试 -->
Set up unit tests (Y/n) n
<!--- 是否需要Nighwatch进行端对端测试 -->
Setup e2e tests with Nightwatch? No
<!-- 选择打包、编译、运行工具 可使用NPM Yarn -->
Should we run `npm install` for you after the project has been created? (recom
mended) 
  Yes, use NPM 
  Yes, use Yarn 
? No, I will handle that myself 
<!--- 初始化完毕 -->
vue-cli · Generated "demo001".

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

To get started:

  cd demo001
  npm install (or if using yarn: yarn)
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack
六、vue项目编译、打包、运行

使用npm install/yarn install进行编译,编译完成后会生成node_modules项目依赖目录
使用npm run build/ yarn run build进行打包,打包完成后会默认生成dist静态项目文件
使用npm run dev/yarn run dev/npm run start/yarn run start进行本地项目启动
使用node serve服务/http-server服务/nginx服务进行部署启动

<!--- serve/http-server -->
serve -s dist/http-server dist

<!--- nginx.conf 配置 -->
server {
    listen       8080;
    server_name  localhost;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

技术图片
Tips:可通过查看package.json配置文件查看可以执行哪些命令
eg:

{
  "name": "demo001",
  "version": "1.0.0",
  "description": "A Vue.js project",
  "author": "swift <aswift@126.com>",
  "private": true,
  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "build": "node build/build.js"
  },
  "dependencies": {
    "vue": "^2.5.2",
    "vue-router": "^3.0.1"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.22.1",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "chalk": "^2.0.1",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.4",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "node-notifier": "^5.1.2",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.2.0",
    "portfinder": "^1.0.13",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.8",
    "postcss-url": "^7.2.1",
    "rimraf": "^2.6.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "uglifyjs-webpack-plugin": "^1.1.1",
    "url-loader": "^0.5.8",
    "vue-loader": "^13.3.0",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.5.2",
    "webpack": "^3.6.0",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-dev-server": "^2.9.1",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 6.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

通过查看scripts脚本配置我们可以运行npm run dev/npm run start/npm run build进行启动、打包操作。

第一个Vue页面

标签:star   erro   shell   reset   code   项目   demo   sel   runtime   

原文地址:https://blog.51cto.com/12012821/2514396

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!