webpack4搭建工程项目,使用eslint代码校验。
工程运行时报错,Parsing error: The keyword ‘import’ is reserved
原因:eslint包没有使用es6
解决:
.eslintrc.js 配置如下
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
ecmaVersion: 6,
ecmaFeatures: {
jsx: true,
modules: true
}
},
env: {
browser: true,
},
}
eslint的npm包如下:
“eslint”: “^6.0.1”,
“eslint-friendly-formatter”: “^4.0.1”,
“eslint-loader”: “^2.1.2”,
“eslint-plugin-html”: “^6.0.0”,
webpack配置中引入eslint
{
test: /\.js$/,
loader: "eslint-loader",
enforce: "pre",
include: [path.resolve(__dirname, "src")], // 指定检查的目录
options: { // 这里的配置项参数将会被传递到 eslint 的 CLIEngine
formatter: require("eslint-friendly-formatter") // 指定错误报告的格式规范
}
}