前端周总结5+vue,egg.js项目初始化

391 阅读1分钟

在家办公第四周,这周五发了工资,心情还是挺不错的,而且湖北的大多数地区新增感染人数连续几天都为零,情况越来越好了,返京指日可待!

想要留下的代码

1.client端创建vue项目

  Client
  npm install -g @vue/cli@3.3.0
  vue —version
  vue create client
  [根据这个网址选的选项](https://www.cnblogs.com/Jimc/p/10278254.html)

2.server端,egg.js项目

 Server
 npm i egg-init -g
 egg-init server --type=simple
 npm i
 npm run dev
 localhost:7001
 [参照这个网址](https://blog.csdn.net/qq_38972119/article/details/89063198)
  1. 最外层
  1)添加代码规范
  npm install -g commitizen
  commitizen init cz-conventional-changelog --save --save-exact
  npm install -g conventional-changelog-cli
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0”
   npm run changelog
  [参照](http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html)
  
  2)git hook
    npm i -D husky lint-staged @commitlint/cli @commitlint/config-conventional
    "scripts": {
       "lint": "eslint . --ext .js,.vue --fix"
     },
    "husky": {
      "hooks": {
        "pre-commit": "lint-staged",
        "commit-msg": "node scripts/validate-commit-msg.js"
      }
    },
   "lint-staged": {
      "*.{js,vue}": [
         "npm run lint",
         "git add"
        ]
    }
   [参照](https://www.jianshu.com/p/cdd749c624d9)

  3)添加eslint
     npm install eslint
     eslint —init
    选择popular下面的standard
    [参照](https://www.jb51.net/article/161346.html)
  
  4)添加文字背景 
     npm install chalk
  
  5)npm-run-all
    npm i npm-run-all --save-dev
    package.json
     "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "serve": "cd client && npm run serve",
        "dev": "cd server && npm run dev",
        "install:client": "cd client && npm install",
        "install:server": "cd server && npm install",
        "install-all": "npm-run-all install:*",
        "changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0"
     },

踩过的坑

1. vue的template中若要使用window下的变量,得在script中的data中声明,否则报错
 data() {
    return {
      a:window.a
    }
  }

学到的新知识

这周忙于项目的搭建,学到了项目初始化过程中要做的事情,阅读了阮一峰的科技爱好者周刊觉得这个写作猫还不错。