dva
dva copied to clipboard
请问如何设置eslint-loader 为webpack 的preloaders?
使用 dva-cli new 了一个项目,想使用 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 里

package.json 的配置如下:
{
"private": true,
"dependencies": {
"antd": "^2.9.1",
"classnames": "^2.2.5",
"draftjs-to-markdown": "^0.4.0",
"dva": "^1.1.0",
"dva-loading": "^0.2.0",
"lodash": "^4.17.4",
"qs": "^6.2.0",
"react": "^15.4.1",
"react-countup": "1.3.0",
"react-dom": "^15.4.1",
"react-draft-wysiwyg": "^1.8.1",
"react-helmet": "^5.0.0",
"recharts": "^0.19.0"
},
"devDependencies": {
"antd": "^2.9.1",
"axios": "^0.15.3",
"babel-eslint": "^6.1.2",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-dva-hmr": "^0.3.2",
"babel-plugin-import": "^1.1.1",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-polyfill": "^6.23.0",
"babel-runtime": "^6.9.2",
"draftjs-to-html": "^0.7.0",
"eslint": "^3.17.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-friendly-formatter": "^2.0.7",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^1.4.2",
"eslint-plugin-react": "^5.1.1",
"jsonp": "^0.2.1",
"less-vars-to-js": "^1.1.2",
"mockjs": "^1.0.1-beta3",
"rc-tween-one": "^1.0.0",
"redbox-react": "^1.2.10"
},
"pre-commit": [
"lint"
],
"scripts": {
"dev": "set BROWSER=none&&roadhog server",
"lint": "eslint --fix --ext .js src",
"build": "roadhog build"
},
"theme": "./src/theme.js",
"standard": {
"parser": "babel-eslint",
"globals": [
"location",
"localStorage"
]
}
}