Skip to content

Commit

Permalink
fix: skip thread-loader when cloning js rules to template compilation…
Browse files Browse the repository at this point in the history
… pipeline

Fixes vuejs/vue#12828
  • Loading branch information
haoqunjiang committed Nov 14, 2022
1 parent 46ffb4d commit fb6ff6e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/plugin-webpack4.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function cloneRuleForRenderFn(rule) {
const resource = rule.resource
const resourceQuery = rule.resourceQuery
let currentResource

const res = {
...rule,
resource: (resource) => {
Expand All @@ -204,6 +205,18 @@ function cloneRuleForRenderFn(rule) {
}
}

// Filter out `thread-loader` from the `use` array.
// Mitigate https://github.com/vuejs/vue/issues/12828
// Note this won't work if the `use` filed is a function
if (Array.isArray(res.use)) {
const isThreadLoader = (loader) => loader === 'thread-loader' || /\/node_modules\/thread-loader\//.test(loader)

res.use = res.use.filter(useEntry => {
const loader = typeof useEntry === 'string' ? useEntry : useEntry.loader
return !isThreadLoader(loader)
})
}

if (rule.rules) {
res.rules = rule.rules.map(cloneRuleForRenderFn)
}
Expand Down
19 changes: 16 additions & 3 deletions lib/plugin-webpack5.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ class VueLoaderPlugin {
const { is27 } = resolveCompiler(compiler.options.context)
let jsRulesForRenderFn = []
if (is27) {
const skipThreadLoader = true
jsRulesForRenderFn = rules
.filter(
(r) =>
r !== rawVueRule &&
(match(r, 'test.js').length > 0 || match(r, 'test.ts').length > 0)
)
.map((rawRule) => cloneRule(rawRule, refs, jsRuleCheck, jsRuleResource))
.map((rawRule) => cloneRule(rawRule, refs, jsRuleCheck, jsRuleResource, skipThreadLoader))
}

// global pitcher (responsible for injecting template compiler loader & CSS
Expand Down Expand Up @@ -216,7 +217,7 @@ const jsRuleResource = (query, resource) =>

let uid = 0

function cloneRule(rawRule, refs, ruleCheck, ruleResource) {
function cloneRule(rawRule, refs, ruleCheck, ruleResource, skipThreadLoader) {
const compiledRule = ruleSetCompiler.compileRule(
`clonedRuleSet-${++uid}`,
rawRule,
Expand All @@ -231,7 +232,19 @@ function cloneRule(rawRule, refs, ruleCheck, ruleResource) {
// fix conflict with config.loader and config.options when using config.use
delete rawRule.loader
delete rawRule.options
rawRule.use = ruleUse

// Filter out `thread-loader` from the `use` array.
// Mitigate https://github.com/vuejs/vue/issues/12828
// Note this won't work if the `use` filed is a function
if (skipThreadLoader && Array.isArray(ruleUse)) {
const isThreadLoader = (loader) => loader === 'thread-loader' || /\/node_modules\/thread-loader\//.test(loader)
rawRule.use = ruleUse.filter(useEntry => {
const loader = typeof useEntry === 'string' ? useEntry : useEntry.loader
return !isThreadLoader(loader)
})
} else {
rawRule.use = ruleUse
}
}

let currentResource
Expand Down

0 comments on commit fb6ff6e

Please sign in to comment.