@@ -5,6 +5,25 @@ const selfPath = require.resolve('../index')
5
5
const templateLoaderPath = require . resolve ( './templateLoader' )
6
6
const stylePostLoaderPath = require . resolve ( './stylePostLoader' )
7
7
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
+
8
27
module . exports = code => code
9
28
10
29
// This pitching loader is responsible for intercepting all vue block requests
@@ -16,17 +35,25 @@ module.exports.pitch = function (remainingRequest) {
16
35
17
36
let loaders = this . loaders
18
37
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
21
40
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
+ }
23
50
}
24
51
25
52
// remove self
26
- loaders = loaders . filter ( l => l . path !== __filename )
53
+ loaders = loaders . filter ( isPitcher )
27
54
28
55
// 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 ) ) {
30
57
return
31
58
}
32
59
@@ -58,7 +85,7 @@ module.exports.pitch = function (remainingRequest) {
58
85
59
86
// Inject style-post-loader before css-loader for scoped CSS and trimming
60
87
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 )
62
89
if ( cssLoaderIndex > - 1 ) {
63
90
const afterLoaders = loaders . slice ( 0 , cssLoaderIndex + 1 )
64
91
const beforeLoaders = loaders . slice ( cssLoaderIndex + 1 )
0 commit comments