forked from luoxue-victor/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-chain.config.js
51 lines (50 loc) · 1.56 KB
/
webpack-chain.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// [eslint-loader 配置]
module.exports = ({ config, options: { eslint: { lintOnSave = false, extensions } }, api }) => {
extensions = extensions || require('./eslintOptions').extensions(api)
return () => {
if (!lintOnSave) return
const path = require('path')
const cwd = api.getCwd()
const { resolveModule, loadModule } = require('@pkb/shared-utils')
const allWarnings = lintOnSave === true || lintOnSave === 'warning'
const allErrors = lintOnSave === 'error'
const eslintPkg =
loadModule('eslint/package.json', cwd, true) ||
loadModule('eslint/package.json', __dirname, true)
const { cacheIdentifier } = api.genCacheConfig(
'eslint-loader',
{
'eslint-loader': require('eslint-loader/package.json').version,
eslint: eslintPkg.version
},
[
'.eslintrc.js',
'.eslintrc.yaml',
'.eslintrc.yml',
'.eslintrc.json',
'.eslintrc',
'package.json'
]
)
config.module
.rule('eslint')
.pre()
.exclude.add(/node_modules/)
.end()
.test(/\.(vue|(j)sx?)$/)
.use('eslint-loader')
.loader(require.resolve('eslint-loader'))
.options({
extensions,
cache: true,
cacheIdentifier,
emitWarning: allWarnings,
emitError: allErrors,
eslintPath: path.dirname(
resolveModule('eslint/package.json', cwd) ||
resolveModule('eslint/package.json', __dirname)
),
formatter: loadModule('eslint/lib/formatters/codeframe', cwd, true)
})
}
}