记录:vue.config.js 中eslint配置错误导致的问题 Child compilation failed:

Error: Child compilation failed:
 Module parse failed: Unexpected token (1:0)
 File was processed with these loaders:
  * ./node_modules/html-webpack-plugin/lib/loader.js
  * ./node_modules/eslint-loader/index.js
 You may need an additional loader to handle the result of these loaders.
 > <!DOCTYPE html>
 | <html lang="en">
 |   <head>:
 SyntaxError: Unexpected toke
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue项目使用ESLint,首先需要安装ESLint和相关插件。可以通过以下命令安装: ``` npm install eslint eslint-plugin-vue babel-eslint eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard --save-dev ``` 安装完成后,在Vue项目根目录下创建一个`.eslintrc.js`文件,并设置ESLint配置。例如,以下是一个简单的配置示例: ```javascript module.exports = { root: true, env: { node: true }, extends: [ "plugin:vue/essential", "eslint:recommended", "@vue/prettier" ], parserOptions: { parser: "babel-eslint" }, rules: { "no-console": process.env.NODE_ENV === "production" ? "error" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off" } }; ``` 在`vue.config.js`,可以使用`chainWebpack`方法将ESLint配置添加到Webpack配置。例如,以下是一个简单的示例: ```javascript module.exports = { chainWebpack: config => { config.module .rule("eslint") .test(/\.(js|vue)$/) .enforce("pre") .use("eslint-loader") .loader("eslint-loader") .options({ formatter: require("eslint-friendly-formatter"), emitWarning: true }) .end(); } }; ``` 上面的代码将创建一个名为`eslint`的Webpack规则,并将其应用于JavaScript和Vue文件。`enforce("pre")`确保此规则在其他规则之前运行。`eslint-loader`将应用于规则,并使用`eslint-friendly-formatter`格式化输出。`emitWarning: true`将告诉WebpackESLint出现警告时继续构建。 完成上述配置后,运行`npm run lint`即可使用ESLint检查项目的代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值