Commit 6f1d404c authored by Evan You's avatar Evan You

fix: should not remove eslint-loader on src import blocks (close #1359)

parent be2384c2
......@@ -5,6 +5,25 @@ const selfPath = require.resolve('../index')
const templateLoaderPath = require.resolve('./templateLoader')
const stylePostLoaderPath = require.resolve('./stylePostLoader')
const isESLintLoader = l => /(\/|\\|@)eslint-loader/.test(l.path)
const isNullLoader = l => /(\/|\\|@)null-loader/.test(l.path)
const isCSSLoader = l => /(\/|\\|@)css-loader/.test(l.path)
const isPitcher = l => l.path !== __filename
const dedupeESLintLoader = loaders => {
const res = []
let seen = false
loaders.forEach(l => {
if (!isESLintLoader(l)) {
res.push(l)
} else if (!seen) {
seen = true
res.push(l)
}
})
return res
}
module.exports = code => code
// This pitching loader is responsible for intercepting all vue block requests
......@@ -16,17 +35,25 @@ module.exports.pitch = function (remainingRequest) {
let loaders = this.loaders
// if this is a language block request, remove eslint-loader to avoid
// duplicate linting.
// if this is a language block request, eslint-loader may get matched
// multiple times
if (query.type) {
loaders = loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path))
// if this is an inline block, since the whole file itself is being linted,
// remove eslint-loader to avoid duplicate linting.
if (/\.vue$/.test(this.resourcePath)) {
loaders = loaders.filter(l => !isESLintLoader(l))
} else {
// This is a src import. Just make sure there's not more than 1 instance
// of eslint present.
loaders = dedupeESLintLoader(loaders)
}
}
// remove self
loaders = loaders.filter(l => l.path !== __filename)
loaders = loaders.filter(isPitcher)
// do not inject if user uses null-loader to void the type (#1239)
if (loaders.some(l => /(\/|\\|@)null-loader/.test(l.path))) {
if (loaders.some(isNullLoader)) {
return
}
......@@ -58,7 +85,7 @@ module.exports.pitch = function (remainingRequest) {
// Inject style-post-loader before css-loader for scoped CSS and trimming
if (query.type === `style`) {
const cssLoaderIndex = loaders.findIndex(l => /(\/|\\|@)css-loader/.test(l.path))
const cssLoaderIndex = loaders.findIndex(isCSSLoader)
if (cssLoaderIndex > -1) {
const afterLoaders = loaders.slice(0, cssLoaderIndex + 1)
const beforeLoaders = loaders.slice(cssLoaderIndex + 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment