@@ -5,6 +5,25 @@ const selfPath = require.resolve('../index')
55const templateLoaderPath = require . resolve ( './templateLoader' )
66const stylePostLoaderPath = require . resolve ( './stylePostLoader' )
77
8+ const isESLintLoader = l => / ( \/ | \\ | @ ) e s l i n t - l o a d e r / . test ( l . path )
9+ const isNullLoader = l => / ( \/ | \\ | @ ) n u l l - l o a d e r / . test ( l . path )
10+ const isCSSLoader = l => / ( \/ | \\ | @ ) c s s - l o a d e r / . test ( l . path )
11+ const isPitcher = l => l . path !== __filename
12+
13+ const dedupeESLintLoader = loaders => {
14+ const res = [ ]
15+ let seen = false
16+ loaders . forEach ( l => {
17+ if ( ! isESLintLoader ( l ) ) {
18+ res . push ( l )
19+ } else if ( ! seen ) {
20+ seen = true
21+ res . push ( l )
22+ }
23+ } )
24+ return res
25+ }
26+
827module . exports = code => code
928
1029// This pitching loader is responsible for intercepting all vue block requests
@@ -16,17 +35,25 @@ module.exports.pitch = function (remainingRequest) {
1635
1736 let loaders = this . loaders
1837
19- // if this is a language block request, remove eslint-loader to avoid
20- // duplicate linting.
38+ // if this is a language block request, eslint-loader may get matched
39+ // multiple times
2140 if ( query . type ) {
22- loaders = loaders . filter ( l => ! / ( \/ | \\ | @ ) e s l i n t - l o a d e r / . test ( l . path ) )
41+ // if this is an inline block, since the whole file itself is being linted,
42+ // remove eslint-loader to avoid duplicate linting.
43+ if ( / \. v u e $ / . test ( this . resourcePath ) ) {
44+ loaders = loaders . filter ( l => ! isESLintLoader ( l ) )
45+ } else {
46+ // This is a src import. Just make sure there's not more than 1 instance
47+ // of eslint present.
48+ loaders = dedupeESLintLoader ( loaders )
49+ }
2350 }
2451
2552 // remove self
26- loaders = loaders . filter ( l => l . path !== __filename )
53+ loaders = loaders . filter ( isPitcher )
2754
2855 // do not inject if user uses null-loader to void the type (#1239)
29- if ( loaders . some ( l => / ( \/ | \\ | @ ) n u l l - l o a d e r / . test ( l . path ) ) ) {
56+ if ( loaders . some ( isNullLoader ) ) {
3057 return
3158 }
3259
@@ -58,7 +85,7 @@ module.exports.pitch = function (remainingRequest) {
5885
5986 // Inject style-post-loader before css-loader for scoped CSS and trimming
6087 if ( query . type === `style` ) {
61- const cssLoaderIndex = loaders . findIndex ( l => / ( \/ | \\ | @ ) c s s - l o a d e r / . test ( l . path ) )
88+ const cssLoaderIndex = loaders . findIndex ( isCSSLoader )
6289 if ( cssLoaderIndex > - 1 ) {
6390 const afterLoaders = loaders . slice ( 0 , cssLoaderIndex + 1 )
6491 const beforeLoaders = loaders . slice ( cssLoaderIndex + 1 )
0 commit comments