vue-cli是用来生成 vue项目的命令行工具,它的使用方法是这样的:
vue init <template-name> <project-name>
第二个参数 template-name 就是我们打算使用的模板,目前,模板是通过github上vue-templates这个组织进行发布。我们通常使用的vue init webpack my-project, 其中webpack指的就是 基于webpack的vuejs初始化模板。
本文就根据webpack这套模板(https://github.com/vuejs-templates/webpack/tree/master/template)
进行介绍,基于的版本是#658
首先来到package.json文件里,package.json是npm的配置文件,里面设定了脚本以及项目依赖的库。 npm run dev 这样的命令就写在package.json里。
{ "name": "my-self-project",//项目名称 "version": "1.0.0",//版本 "description": "A Vue.js project",//描述 "author": "shangxiaofei <shangxiaofei3@163.com>",//作者 "private": true,//是否私人项目 "scripts": { "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",//// npm run dev 的 dev,使用node执行 build/dev-server.js "start": "npm run dev",// npm run start 跑的是同样的命令 "build": "node build/build.js"//npm run build 跑的是 node build/build.js // 以下脚本为单元测试用到的脚本 "unit": "jest --config test/unit/jest.conf.js --coverage", "e2e": "node test/e2e/runner.js", "test": "npm run unit && npm run e2e", "lint": "eslint --ext .js,.vue src test/unit test/e2e/specs", }, // dependencies 设定的是项目里使用的依赖,devDependencies设定的是开发使用的依赖 "dependencies": { "vue": "^2.5.2",// 项目依赖vue.js "vue-router": "^3.0.1"// 项目依赖vue-router }, "devDependencies": { "autoprefixer": "^7.1.2",//是用于给css3属性自动加属性前缀的 // babel相关的都是用于处理es6语法的 "babel-core": "^6.22.1", "babel-eslint": "^8.2.1", "babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-jest": "^21.0.2", "babel-loader": "^7.1.1", "babel-plugin-dynamic-import-node": "^1.2.0", "babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.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", "babel-register": "^6.22.0", "chalk": "^2.0.1", "chromedriver": "^2.27.2", "copy-webpack-plugin": "^4.0.1", "cross-spawn": "^5.0.1", "css-loader": "^0.28.0", "eslint": "^4.15.0", "eslint-config-standard": "^10.2.1", "eslint-friendly-formatter": "^3.0.0", "eslint-loader": "^1.7.1", "eslint-plugin-import": "^2.7.0", "eslint-plugin-node": "^5.2.0", "eslint-plugin-promise": "^3.4.0", "eslint-plugin-standard": "^3.0.1", "eslint-plugin-vue": "^4.0.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", "jest": "^22.0.4", "jest-serializer-vue": "^0.3.0", "nightwatch": "^0.9.12", "node-notifier": "^5.1.2", "optimize-css-assets-webpack-plugin": "^3.2.0", "ora": "^1.2.0",// 命令行里自动运行的信息提示 "postcss-import": "^11.0.0", "postcss-loader": "^2.0.8", "postcss-url": "^7.2.1", "rimraf": "^2.6.0",// 跑shell命令 rm-rf 的工具 "selenium-server": "^3.0.1", "semver": "^5.3.0", "shelljs": "^0.7.6", "uglifyjs-webpack-plugin": "^1.1.1", "url-loader": "^0.5.8",// 配合webpack的加载器 "vue-jest": "^1.0.2", "vue-loader": "^13.3.0",// 配合webpack的加载器 "vue-style-loader": "^3.0.1",// 配合webpack的加载器 "vue-template-compiler": "^2.5.2",// vue-template-compiler,可能是配合离线版vue // webpack相关的用于,把图片,*.vue, *.js, 这些组合成最终的项目,webpack-dev用于跑测试服务器 "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" ] }
作者:fishenal
链接:https://www.imooc.com/article/17770?block_id=tuijian_wz
来源:慕课网
本文原创发布于慕课网 ,转载请注明出处,谢谢合作