Skip to content

Commit a1af343

Browse files
ktsnyyx990803
authored andcommitted
fix: avoid generating custom block when there is only cache-loader (#1493)
1 parent daca937 commit a1af343

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
*.log
55
example/dist
66
docs/.vuepress/dist
7+
test/.cache

Diff for: lib/loaders/pitcher.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const stylePostLoaderPath = require.resolve('./stylePostLoader')
88
const isESLintLoader = l => /(\/|\\|@)eslint-loader/.test(l.path)
99
const isNullLoader = l => /(\/|\\|@)null-loader/.test(l.path)
1010
const isCSSLoader = l => /(\/|\\|@)css-loader/.test(l.path)
11+
const isCacheLoader = l => /(\/|\\|@)cache-loader/.test(l.path)
1112
const isPitcher = l => l.path !== __filename
1213

1314
const dedupeESLintLoader = loaders => {
@@ -24,6 +25,23 @@ const dedupeESLintLoader = loaders => {
2425
return res
2526
}
2627

28+
const shouldIgnoreCustomBlock = loaders => {
29+
const actualLoaders = loaders.filter(loader => {
30+
// vue-loader
31+
if (loader.path === selfPath) {
32+
return false
33+
}
34+
35+
// cache-loader
36+
if (isCacheLoader(loader)) {
37+
return false
38+
}
39+
40+
return true
41+
})
42+
return actualLoaders.length === 0
43+
}
44+
2745
module.exports = code => code
2846

2947
// This pitching loader is responsible for intercepting all vue block requests
@@ -128,11 +146,9 @@ module.exports.pitch = function (remainingRequest) {
128146
return `export * from ${request}`
129147
}
130148

131-
// if a custom block has no other matching loader other than vue-loader itself,
132-
// we should ignore it
133-
if (query.type === `custom` &&
134-
loaders.length === 1 &&
135-
loaders[0].path === selfPath) {
149+
// if a custom block has no other matching loader other than vue-loader itself
150+
// or cache-loader, we should ignore it
151+
if (query.type === `custom` && shouldIgnoreCustomBlock(loaders)) {
136152
return ``
137153
}
138154

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"babel-core": "^6.26.0",
4848
"babel-loader": "^7.1.4",
4949
"babel-preset-env": "^1.6.1",
50+
"cache-loader": "^2.0.1",
5051
"conventional-changelog-cli": "^1.3.22",
5152
"css-loader": "^1.0.0",
5253
"eslint": "^4.19.0",

Diff for: test/custom.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path')
12
const {
23
bundle,
34
mockBundleAndRun
@@ -69,3 +70,26 @@ test('custom blocks can be ignored', done => {
6970
done()
7071
})
7172
})
73+
74+
test('custom blocks can be ignored even if cache-loader processes them', done => {
75+
bundle(
76+
{
77+
entry: 'custom-language.vue',
78+
module: {
79+
rules: [
80+
{
81+
test: /.vue$/,
82+
loader: 'cache-loader',
83+
options: {
84+
cacheDirectory: path.resolve(__dirname, '.cache')
85+
}
86+
}
87+
]
88+
}
89+
},
90+
code => {
91+
expect(code).not.toContain(`describe('example'`)
92+
done()
93+
}
94+
)
95+
})

Diff for: yarn.lock

+21
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,17 @@ cache-loader@^1.2.2:
24102410
neo-async "^2.5.0"
24112411
schema-utils "^0.4.2"
24122412

2413+
cache-loader@^2.0.1:
2414+
version "2.0.1"
2415+
resolved "https://registry.yarnpkg.com/cache-loader/-/cache-loader-2.0.1.tgz#5758f41a62d7c23941e3c3c7016e6faeb03acb07"
2416+
integrity sha512-V99T3FOynmGx26Zom+JrVBytLBsmUCzVG2/4NnUKgvXN4bEV42R1ERl1IyiH/cvFIDA1Ytq2lPZ9tXDSahcQpQ==
2417+
dependencies:
2418+
loader-utils "^1.1.0"
2419+
mkdirp "^0.5.1"
2420+
neo-async "^2.6.0"
2421+
normalize-path "^3.0.0"
2422+
schema-utils "^1.0.0"
2423+
24132424
call-me-maybe@^1.0.1:
24142425
version "1.0.1"
24152426
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
@@ -7630,6 +7641,11 @@ neo-async@^2.5.0:
76307641
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.5.2.tgz#489105ce7bc54e709d736b195f82135048c50fcc"
76317642
integrity sha512-vdqTKI9GBIYcAEbFAcpKPErKINfPF5zIuz3/niBfq8WUZjpT2tytLlFVrBgWdOtqI4uaA/Rb6No0hux39XXDuw==
76327643

7644+
neo-async@^2.6.0:
7645+
version "2.6.0"
7646+
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.0.tgz#b9d15e4d71c6762908654b5183ed38b753340835"
7647+
integrity sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==
7648+
76337649
next-tick@1:
76347650
version "1.0.0"
76357651
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
@@ -7812,6 +7828,11 @@ normalize-path@^2.0.1, normalize-path@^2.1.1:
78127828
dependencies:
78137829
remove-trailing-separator "^1.0.1"
78147830

7831+
normalize-path@^3.0.0:
7832+
version "3.0.0"
7833+
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
7834+
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
7835+
78157836
normalize-range@^0.1.2:
78167837
version "0.1.2"
78177838
resolved "https://registry.yarnpkg.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942"

0 commit comments

Comments
 (0)