在使用roadhog 后如何设置eslint-loader 为webpack 的preloaders?
想使用 eslint-loader 在编译前检查,添加了 webpack.config.js,代码如下:
module.exports = function (webpackConfig, env) {
// eslint all js before other loaders
webpackConfig.module.preLoaders = [{
test: /\.(js)$/,
loader: 'eslint-loader',
exclude: /node_modules/,
options: {
formatter: require('eslint-friendly-formatter')
}
}]
console.log(webpackConfig)
return webpackConfig
}
但执行 npm run dev 时报错
Failed to compile.
Error in multi index
Module not found: 'eslint-loader' in D:\devtool\WNMP\www\mycode\antd-demo3
@ multi index

但我很确定 eslint-loader 已经install 了,并且存在 node_modules 里

这个没试过,我现在是在编辑器上安装了插件,每次报错时代码会按照.editorconfig的配置自动格式化
编辑器配置
ˊ_>ˋ 我也装了,但是由于“不可抗力”的因素,不能保证所有人都装...
因为这个项目用的是SVN,连pre-commit 都用不了。
之前另外一个 vue 的项目是直接用 eslint-loader 在编译前检查的,会直接抛错,感觉这个强制性很够,但用了roadhog 后一直抛错,之前用 ant-tool + dora 的时候倒是没问题的 (:з」∠)
roadhog 的作者也不回我... 真的找了超久也不知道为什么会 module not found 心累
webpackConfig.module.rules = [{
enforce: 'pre',
test: /\.(js)$/,
loader: 'eslint-loader',
exclude: /node_modules/,
options: {
formatter: require('eslint-friendly-formatter'),
},
}]
刚刚查了下webpack文档module没有preLoaders 属性啊,
eslint-loader的用法中设置了enforce: 'pre'
你看看这样能work不
@zuiidea Thx,preLoaders 是webpack 1.x 的用法,我看了下 roadhog 的 package.json,它的版本是^1.14.0,所以用了preLoaders 。
rules 倒是不报错,可也不生效 (:з」∠)
我还是觉得是 roadhog merge config 的时候没做好,但我也找不到在哪里 (:з」∠)
@IssaTan1990 我知道啦,今天看给css的className的时候发现loader写的是”css“,"style”等等, 原因是cofig中
{
resolveLoader: {
moduleTemplates: [
'*-loader',
],
},
}
所以应该这样写
webpackConfig.module.preLoaders = [{
test: /\.(js)$/,
loader: 'eslint',
enforce: 'pre'
}]
已测试 https://github.com/zuiidea/antd-admin/commit/2e3cb5970d08110d92174f025b99a097e05c2722