Skip to content

Vue CLI 2 迁移到 Vue CLI 3

Published: at 08:00 AM

vue-cli2 to vue-cli3

why

新原因:

历史遗留问题:

迁移过程

  1. 本地安装 vue-cli3,创建项目 IdcUI-cli3,创建时选择 vuex、vue-router、Airbnb lint 等等。
  2. 将 IdcUI 的文件,复制一份到 IdcUI-cli3 中,整理下 package.json 中的依赖,暂时项目依赖还是用原来的,暂时不升级、否则可能会死人、后期脚手架稳定后再考虑升级项目依赖(比如 iview3.0)
  3. 调整 eslint 规则,虽然 Airbnb 大部分规则是合适的,但是少部分还是可以去掉的。
  4. 调整 IDE 的配置,VS Code 的配置。
  5. 调整静态资源的路径。
  6. 根据eslint规则,修改业务代码。

迁移问题解决

eslint 规则

package.json下的eslintConfig

"eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "@vue/airbnb"
    ],
    "rules": {
      "max-len": "off",
      "vue/no-parsing-error": [
        2,
        {
          "x-invalid-end-tag": false
        }
      ],
      "no-param-reassign": [
        "error",
        {
          "props": false
        }
      ],
      "consistent-return": "off"
    },
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },

暂时去掉git hook,待将所有问题修改完,再次开启。

"gitHooks": {
    "pre-commit": "lint-staged"
  },

初期修复时,可以使用

// 指定目录,非常方便
npm run lint src/views/index/

VS Code 配置

{
  "prettier.singleQuote": true,
  "prettier.trailingComma": "all",
  "prettier.arrowParens": "always",
  "editor.insertSpaces": true,
  "editor.tabSize": 2,
  "editor.formatOnType": true,

  "prettier.tabWidth": 2,
  "prettier.printWidth": 100,
  "editor.detectIndentation": true,
  "vetur.validation.template": false
}

eslint问题汇总

  1. (array-callback-return) forEach/map

注意:

  1. 不能热更新,解决( npm config set registry https://registry.npm.taobao.org)