先来看下错误
npm run build
timsdk-demo@2.0.0 build G:\tim_front
node node_modules/@vue/cli-service/bin/vue-cli-service.js build
- Building for production…
ERROR Failed to compile with 1 errors 15:40:56
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
No ESLint configuration found.
at PoolWorker.fromErrorObj (G:\tim_front\node_modules\thread-loader\dist\WorkerPool.js:262:12)
at G:\tim_front\node_modules\thread-loader\dist\WorkerPool.js:204:29
at mapSeries (G:\tim_front\node_modules\neo-async\async.js:3625:14)
at Config.getLocalConfigHierarchy (G:\tim_front\node_modules\eslint\lib\config.js:268:39)
at Config.getConfigHierarchy (G:\tim_front\node_modules\eslint\lib\config.js:192:43)
at Config.getConfigVector (G:\tim_front\node_modules\eslint\lib\config.js:299:21)
at Config.getConfig (G:\tim_front\node_modules\eslint\lib\config.js:342:29)
at processText (G:\tim_front\node_modules\eslint\lib\cli-engine.js:181:33)
at CLIEngine.executeOnText (G:\tim_front\node_modules\eslint\lib\cli-engine.js:690:40)
at lint (G:\tim_front\node_modules\eslint-loader\index.js:278:17)
at transform (G:\tim_front\node_modules\eslint-loader\index.js:252:18)
at G:\tim_front\node_modules\loader-fs-cache\index.js:127:18
at ReadFileContext.callback (G:\tim_front\node_modules\loader-fs-cache\index.js:31:14)
贴个图,方便看
这个报错原因就是vscode有一个eslint规范代码插件,导致我们的项目报错。所以我们需要配置一下eslint就好了。
一、安装eslint依次执行以下命令:
npm init -y
npm install eslint --save-dev
./node_modules/.bin/eslint --init 初始化配置文件
如果在这几步里面报错,先删掉node_modules,npm i重装一下,或者检查一下上面的命令有没有输错。
成功执行的情况下如图:
成功的话看下项目根目录会有一个**.eslintrc.js文件**
二、配置.eslintrc.js文件
有点长,在网上搜了好几个版本,这个比较全面没有报错
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},
env: {
browser: true,
node: true,
es6: true,
},
extends: ['plugin:vue/recommended', 'eslint:recommended'],
// add your custom rules here
//it is base on https://github.com/vuejs/eslint-config-vue
rules: {
"vue/max-attributes-per-line": [2, {
"singleline": 10,
"multiline": {
"max": 1,
"allowFirstLine": false
}
}],
"vue/singleline-html-element-content-newline": "off",
"vue/multiline-html-element-content-newline":"off",
"vue/name-property-casing": ["error", "PascalCase"],
"vue/no-v-html": "off",
'accessor-pairs': 2,
'arrow-spacing': [2, {
'before': true,
'after': true
}],
'block-spacing': [</