Skip to content

Commit ff0f97b

Browse files
committed
feat(eslint): enable caching
1 parent be8d317 commit ff0f97b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

packages/@vue/cli-plugin-eslint/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module.exports = (api, { lintOnSave }) => {
22
if (lintOnSave) {
33
const extensions = require('./eslintOptions').extensions(api)
4+
const cacheIdentifier = genCacheIdentifier(api.resolve('.'))
5+
46
api.chainWebpack(webpackConfig => {
57
webpackConfig.module
68
.rule('eslint')
@@ -14,6 +16,8 @@ module.exports = (api, { lintOnSave }) => {
1416
.loader('eslint-loader')
1517
.options({
1618
extensions,
19+
cache: true,
20+
cacheIdentifier,
1721
emitWarning: lintOnSave !== 'error',
1822
formatter: require('eslint/lib/formatters/codeframe')
1923
})
@@ -34,3 +38,33 @@ module.exports = (api, { lintOnSave }) => {
3438
require('./lint')(args, api)
3539
})
3640
}
41+
42+
// eslint-loader doesn't bust cache when eslint config changes
43+
// so we have to manually generate a cache identifier that takes the config
44+
// into account.
45+
function genCacheIdentifier (context) {
46+
const fs = require('fs')
47+
const path = require('path')
48+
const files = [
49+
'.eslintrc.js',
50+
'.eslintrc.yaml',
51+
'.eslintrc.yml',
52+
'.eslintrc.json',
53+
'.eslintrc',
54+
'package.json'
55+
]
56+
57+
const configTimeStamp = (() => {
58+
for (const file of files) {
59+
if (fs.existsSync(path.join(context, file))) {
60+
return fs.statSync(file).mtimeMs
61+
}
62+
}
63+
})()
64+
65+
return JSON.stringify({
66+
'eslint-loader': require('eslint-loader/package.json').version,
67+
'eslint': require('eslint/package.json').version,
68+
'config': configTimeStamp
69+
})
70+
}

0 commit comments

Comments
 (0)