Skip to content

Commit

Permalink
feat: support eslint check via process.env.ESLINT (#1819)
Browse files Browse the repository at this point in the history
Close #1770

现在有个问题,配置生效了,但是打印的日志里**定位文件错误**,都是定在了 eslint-load.js。
  • Loading branch information
xiaohuoni authored and sorrycc committed Jan 11, 2019
1 parent de34bcc commit dcbd5d8
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .prettierignore
Expand Up @@ -3,3 +3,8 @@
**/bin/*.js
**/website/*.js
packages/umi-build-dev/src/plugins/commands/block/index.js
packages/af-webpack/src/getConfig/index.js
packages/af-webpack/src/getConfig/css.js
packages/af-webpack/src/getConfig/eslint.js
packages/af-webpack/src/getConfig/dev.js
packages/af-webpack/src/getConfig/prod.js
9 changes: 8 additions & 1 deletion packages/af-webpack/package.json
Expand Up @@ -31,6 +31,13 @@
"didyoumean": "1.2.1",
"duplicate-package-checker-webpack-plugin": "3.0.0",
"es5-imcompatible-versions": "^0.1.25",
"eslint": "5.12.0",
"eslint-config-umi": "1.3.0",
"eslint-loader": "2.1.1",
"eslint-plugin-flowtype": "2.50.3",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-react": "7.12.3",
"file-loader": "2.0.0",
"fork-ts-checker-webpack-plugin": "0.5.0",
"friendly-errors-webpack-plugin": "1.7.0",
Expand All @@ -46,7 +53,7 @@
"postcss": "7.0.8",
"postcss-flexbugs-fixes": "4.1.0",
"postcss-loader": "3.0.0",
"react-dev-utils": "6.1.1",
"react-dev-utils": "7.0.1",
"react-error-overlay": "5.1.0",
"requireindex": "1.2.0",
"resolve": "1.8.1",
Expand Down
26 changes: 26 additions & 0 deletions packages/af-webpack/src/getConfig/eslint.js
@@ -0,0 +1,26 @@
import eslintFormatter from 'react-dev-utils/eslintFormatter';

export default function(webpackConfig, opts) {
const eslintOptions = {
formatter: eslintFormatter,
baseConfig: {
extends: [require.resolve('eslint-config-umi')],
},
ignore: false,
eslintPath: require.resolve('eslint'),
useEslintrc: false,
};

webpackConfig.module
.rule('eslint')
.test(/\.(js|jsx)$/)
.include.add(opts.cwd)
.end()
.exclude
.add(/node_modules/)
.end()
.enforce('pre')
.use('eslint-loader')
.loader(require.resolve('eslint-loader'))
.options(eslintOptions);
}
5 changes: 5 additions & 0 deletions packages/af-webpack/src/getConfig/index.js
Expand Up @@ -144,6 +144,11 @@ export default function(opts) {
];
}

// module -> eslint
if (process.env.ESLINT && process.env.ESLINT !== 'none') {
require('./eslint').default(webpackConfig, opts);
}

// Avoid "require is not defined" errors
webpackConfig.module
.rule('mjs-require')
Expand Down

0 comments on commit dcbd5d8

Please sign in to comment.