diff --git a/packages/@vue/cli-plugin-eslint/index.js b/packages/@vue/cli-plugin-eslint/index.js index 3dd40fad1..410bc2915 100644 --- a/packages/@vue/cli-plugin-eslint/index.js +++ b/packages/@vue/cli-plugin-eslint/index.js @@ -1,6 +1,8 @@ module.exports = (api, { lintOnSave }) => { if (lintOnSave) { const extensions = require('./eslintOptions').extensions(api) + const cacheIdentifier = genCacheIdentifier(api.resolve('.')) + api.chainWebpack(webpackConfig => { webpackConfig.module .rule('eslint') @@ -14,6 +16,8 @@ module.exports = (api, { lintOnSave }) => { .loader('eslint-loader') .options({ extensions, + cache: true, + cacheIdentifier, emitWarning: lintOnSave !== 'error', formatter: require('eslint/lib/formatters/codeframe') }) @@ -34,3 +38,33 @@ module.exports = (api, { lintOnSave }) => { require('./lint')(args, api) }) } + +// eslint-loader doesn't bust cache when eslint config changes +// so we have to manually generate a cache identifier that takes the config +// into account. +function genCacheIdentifier (context) { + const fs = require('fs') + const path = require('path') + const files = [ + '.eslintrc.js', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + '.eslintrc', + 'package.json' + ] + + const configTimeStamp = (() => { + for (const file of files) { + if (fs.existsSync(path.join(context, file))) { + return fs.statSync(file).mtimeMs + } + } + })() + + return JSON.stringify({ + 'eslint-loader': require('eslint-loader/package.json').version, + 'eslint': require('eslint/package.json').version, + 'config': configTimeStamp + }) +} diff --git a/packages/@vue/cli-plugin-typescript/index.js b/packages/@vue/cli-plugin-typescript/index.js index 0528e1dc8..a1ea0726d 100644 --- a/packages/@vue/cli-plugin-typescript/index.js +++ b/packages/@vue/cli-plugin-typescript/index.js @@ -50,6 +50,7 @@ module.exports = (api, { }) // make sure to append TSX suffix tsxRule.use('ts-loader').loader('ts-loader').tap(options => { + options = Object.assign({}, options) delete options.appendTsSuffixTo options.appendTsxSuffixTo = [/\.vue$/] return options diff --git a/packages/@vue/cli-service/package.json b/packages/@vue/cli-service/package.json index 3d39e42af..ee1048d7d 100644 --- a/packages/@vue/cli-service/package.json +++ b/packages/@vue/cli-service/package.json @@ -59,7 +59,7 @@ "thread-loader": "^1.1.5", "uglifyjs-webpack-plugin": "^1.2.5", "url-loader": "^1.0.1", - "vue-loader": "^15.0.11", + "vue-loader": "^15.1.0", "vue-template-compiler": "^2.5.16", "webpack": "^4.8.2", "webpack-chain": "^4.8.0", diff --git a/packages/@vue/cli/__tests__/Generator.spec.js b/packages/@vue/cli/__tests__/Generator.spec.js index 38fa535bc..00789ecd4 100644 --- a/packages/@vue/cli/__tests__/Generator.spec.js +++ b/packages/@vue/cli/__tests__/Generator.spec.js @@ -4,7 +4,7 @@ const fs = require('fs-extra') const path = require('path') const Generator = require('../lib/Generator') const { logs } = require('@vue/cli-shared-utils') -const stringifyJS = require('../util/stringifyJS') +const stringifyJS = require('../lib/util/stringifyJS') // prepare template fixtures const templateDir = path.resolve(__dirname, 'template') diff --git a/yarn.lock b/yarn.lock index 4a1ef4859..56a9f47d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11490,9 +11490,9 @@ vue-jest@^2.6.0: tsconfig "^7.0.0" vue-template-es2015-compiler "^1.6.0" -vue-loader@^15.0.11: - version "15.0.11" - resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.0.11.tgz#b41dee864cdeb0012c8a2c02a66b13459e45e16e" +vue-loader@^15.1.0: + version "15.1.0" + resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.1.0.tgz#82a2a5c310951aba17ad5d8680fe016c77d37e80" dependencies: "@vue/component-compiler-utils" "^1.2.1" hash-sum "^1.0.2"