最近学习前后端的全栈项目,头大的要命,慢慢发现,自己越用功想研究一门技术,越发现不懂的慢慢越多,真是有点打击信心。
好在,今天终于把前后端的基础框架搭起来了,后续文章分享学习经验。
今天分享是前后端联动启动
首先安装concurrently
然后安装vue项目
vue -V 我现在已经装上3.0版本了。
vue create client
按照提示把vue-router vuex eslint sass等安装好,自动安装依赖包,稍等一会,装好前端vue项目后,我们启动一下,8080端口跑起来就ctrl+c退出前端
接下来,修改前端vue的package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"start": "npm run serve"
},
"dependencies": {
"vue": "^2.5.17",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.1.1",
"@vue/cli-plugin-eslint": "^3.1.1",
"@vue/cli-service": "^3.1.1",
"@vue/eslint-config-standard": "^4.0.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0-0",
"node-sass": "^4.9.0",
"sass-loader": "^7.0.1",
"vue-template-compiler": "^2.5.17"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"@vue/standard"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
注意,主要增加了start命令 npm run serve
接下来,修改后端koa的配置
也是同样打开package.json
{
"name": "resfulapi",
"version": "1.0.0",
"description": "resfulAPI",
"main": "app.js",
"scripts": {
"client-install": "npm install --prefix client",
"client": "npm start --prefix client",
"start": "node app.js",
"server": "nodemon app.js",
"lint": "eslint --fix --ext .js,.vue",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "ISC",
"dependencies": {
"art-template": "^4.13.2",
"axios": "^0.18.0",
"babel-eslint": "^10.0.1",
"bcrypt": "^3.0.2",
"concurrently": "^4.1.0",
"eslint": "^4.15.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-html": "^5.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^4.7.1",
"gravatar": "^1.8.0",
"jsonwebtoken": "^8.4.0",
"koa": "^2.6.2",
"koa-art-template": "^1.1.1",
"koa-bodyparser": "^4.2.1",
"koa-json": "^2.0.2",
"koa-jwt": "^3.5.1",
"koa-passport": "^4.1.1",
"koa-router": "^7.4.0",
"koa-static": "^5.0.0",
"mongoose": "^5.3.15",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
}
}
注意,也是修改了启动命令,主要是这三条
"client-install": "npm install --prefix client" 联动启动前,先安装client目录下的vue项目的npm包
"client": "npm start --prefix client", 联动启动前先启动client目录下npm start ,看package,json里,我们已经配置了npm start
"dev": "concurrently \"npm run server\" \"npm run client\""
联动启动前后端项目
这样,我们用concurrently来联动启动我们的前后端项目,npm run dev,快乐的启动吧!
最近脑子感觉不够用,一个人默默的啃代码,写下来,防止以后再找资料