From 5f0d57fd605dbbd744dfa2d9ba3bff47c5d06f12 Mon Sep 17 00:00:00 2001 From: GONGONGONG <506419689@qq.com> Date: Thu, 16 Dec 2021 17:04:35 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20=E4=BC=98=E5=8C=96js=E3=80=81ts=20l?= =?UTF-8?q?int=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ frontend/.eslintrc.js | 6 ++++++ frontend/README.md | 19 +++++++++++++++++++ frontend/package.json | 1 + 4 files changed, 29 insertions(+) diff --git a/.gitignore b/.gitignore index 714f743e7..77f66dd3a 100644 --- a/.gitignore +++ b/.gitignore @@ -179,3 +179,6 @@ tests/postman/bkman .helm !env/ + +# frontend +vetur.config.js diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index bff430ba2..fd7a232c8 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -1,5 +1,11 @@ module.exports = { root: true, + // 前端项目不在根目录时, 配合 vetur.config.js 来保证eslint正确解析ts的配置 + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir: __dirname, + sourceType: 'module', + }, extends: ['plugin:vue/recommended', '@bkui/eslint-config-bk/tsvue'], globals: { // value 为 true 允许被重写,为 false 不允许被重写 diff --git a/frontend/README.md b/frontend/README.md index c1bdc03e8..704e8d0a6 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -22,4 +22,23 @@ npm install npm run dll // 4. 启动服务 npm run dev +``` + +### eslint +前端文件不处于根目录时, eslint不生效。 根目录新建 `vetur.config.js` 文件。引导正确js、ts检查配置文件路径, 同下: +```javascript +module.exports = { + projects: [ + './frontend', + { + root: './frontend', + package: './package.json', + tsconfig: './tsconfig.json', + snippetFolder: './.vscode/vetur/snippets', + globalComponents: [ + './src/components/**/*.vue' + ] + } + ] +} ``` \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index f44ddb02f..96962bd0b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,6 +11,7 @@ "build": "better-npm-run build", "build:analyzer": "better-npm-run build:analyzer", "dll": "better-npm-run dll", + "lint": "eslint --ext .ts,.js,.vue src/", "fix": "eslint --fix --ext .ts,.js,.vue src/", "check-dll": "ts-node --project build/tsconfig.json build/check-dll.ts" },