提交 05275209 编写于 作者: Q qiang

fix(vue-cli-plugin-uni): update plugin-webpack5.js

上级 71d2bbd4
...@@ -6,28 +6,48 @@ const BasicMatcherRulePlugin = require('webpack/lib/rules/BasicMatcherRulePlugin ...@@ -6,28 +6,48 @@ const BasicMatcherRulePlugin = require('webpack/lib/rules/BasicMatcherRulePlugin
const RuleSetCompiler = require('webpack/lib/rules/RuleSetCompiler') const RuleSetCompiler = require('webpack/lib/rules/RuleSetCompiler')
const UseEffectRulePlugin = require('webpack/lib/rules/UseEffectRulePlugin') const UseEffectRulePlugin = require('webpack/lib/rules/UseEffectRulePlugin')
const objectMatcherRulePlugins = []
try {
const ObjectMatcherRulePlugin = require('webpack/lib/rules/ObjectMatcherRulePlugin')
objectMatcherRulePlugins.push(
new ObjectMatcherRulePlugin('assert', 'assertions'),
new ObjectMatcherRulePlugin('descriptionData')
)
} catch (e) {
const DescriptionDataMatcherRulePlugin = require('webpack/lib/rules/DescriptionDataMatcherRulePlugin')
objectMatcherRulePlugins.push(new DescriptionDataMatcherRulePlugin())
}
const ruleSetCompiler = new RuleSetCompiler([ const ruleSetCompiler = new RuleSetCompiler([
new BasicMatcherRulePlugin('test', 'resource'), new BasicMatcherRulePlugin('test', 'resource'),
new BasicMatcherRulePlugin('mimetype'),
new BasicMatcherRulePlugin('dependency'),
new BasicMatcherRulePlugin('include', 'resource'), new BasicMatcherRulePlugin('include', 'resource'),
new BasicMatcherRulePlugin('exclude', 'resource', true), new BasicMatcherRulePlugin('exclude', 'resource', true),
new BasicMatcherRulePlugin('resource'),
new BasicMatcherRulePlugin('conditions'), new BasicMatcherRulePlugin('conditions'),
new BasicMatcherRulePlugin('resource'),
new BasicMatcherRulePlugin('resourceQuery'), new BasicMatcherRulePlugin('resourceQuery'),
new BasicMatcherRulePlugin('resourceFragment'),
new BasicMatcherRulePlugin('realResource'), new BasicMatcherRulePlugin('realResource'),
new BasicMatcherRulePlugin('issuer'), new BasicMatcherRulePlugin('issuer'),
new BasicMatcherRulePlugin('compiler'), new BasicMatcherRulePlugin('compiler'),
...objectMatcherRulePlugins,
new BasicEffectRulePlugin('type'), new BasicEffectRulePlugin('type'),
new BasicEffectRulePlugin('sideEffects'), new BasicEffectRulePlugin('sideEffects'),
new BasicEffectRulePlugin('parser'), new BasicEffectRulePlugin('parser'),
new BasicEffectRulePlugin('resolve'), new BasicEffectRulePlugin('resolve'),
new BasicEffectRulePlugin('generator'),
new UseEffectRulePlugin() new UseEffectRulePlugin()
]) ])
class VueLoaderPlugin { class VueLoaderPlugin {
apply (compiler) { apply (compiler) {
const normalModule = compiler.webpack
? compiler.webpack.NormalModule
: require('webpack/lib/NormalModule')
// add NS marker so that the loader can detect and report missing plugin // add NS marker so that the loader can detect and report missing plugin
compiler.hooks.compilation.tap(id, compilation => { compiler.hooks.compilation.tap(id, compilation => {
const normalModuleLoader = require('webpack/lib/NormalModule').getCompilationHooks(compilation).loader const normalModuleLoader = normalModule.getCompilationHooks(compilation).loader
normalModuleLoader.tap(id, loaderContext => { normalModuleLoader.tap(id, loaderContext => {
loaderContext[NS] = true loaderContext[NS] = true
}) })
...@@ -38,6 +58,10 @@ class VueLoaderPlugin { ...@@ -38,6 +58,10 @@ class VueLoaderPlugin {
let vueRules = [] let vueRules = []
for (const rawRule of rules) { for (const rawRule of rules) {
// skip rules with 'enforce'. eg. rule for eslint-loader
if (rawRule.enforce) {
continue
}
// skip the `include` check when locating the vue rule // skip the `include` check when locating the vue rule
const clonedRawRule = Object.assign({}, rawRule) const clonedRawRule = Object.assign({}, rawRule)
delete clonedRawRule.include delete clonedRawRule.include
...@@ -71,7 +95,7 @@ class VueLoaderPlugin { ...@@ -71,7 +95,7 @@ class VueLoaderPlugin {
) )
} }
// get the normlized "use" for vue files // get the normalized "use" for vue files
const vueUse = vueRules.filter(rule => rule.type === 'use').map(rule => rule.value) const vueUse = vueRules.filter(rule => rule.type === 'use').map(rule => rule.value)
// get vue-loader options // get vue-loader options
...@@ -110,6 +134,7 @@ class VueLoaderPlugin { ...@@ -110,6 +134,7 @@ class VueLoaderPlugin {
const pitcher = { const pitcher = {
loader: require.resolve('./loaders/pitcher'), loader: require.resolve('./loaders/pitcher'),
resourceQuery: query => { resourceQuery: query => {
if (!query) { return false }
const parsed = qs.parse(query.slice(1)) const parsed = qs.parse(query.slice(1))
return parsed.vue != null return parsed.vue != null
}, },
...@@ -128,8 +153,9 @@ class VueLoaderPlugin { ...@@ -128,8 +153,9 @@ class VueLoaderPlugin {
} }
} }
let uid = 0
function cloneRule (rawRule, refs) { function cloneRule (rawRule, refs) {
const rules = ruleSetCompiler.compileRules('ruleSet', [{ const rules = ruleSetCompiler.compileRules(`clonedRuleSet-${++uid}`, [{
rules: [rawRule] rules: [rawRule]
}], refs) }], refs)
let currentResource let currentResource
...@@ -182,6 +208,10 @@ function cloneRule (rawRule, refs) { ...@@ -182,6 +208,10 @@ function cloneRule (rawRule, refs) {
delete res.test delete res.test
if (rawRule.rules) {
res.rules = rawRule.rules.map(rule => cloneRule(rule, refs))
}
if (rawRule.oneOf) { if (rawRule.oneOf) {
res.oneOf = rawRule.oneOf.map(rule => cloneRule(rule, refs)) res.oneOf = rawRule.oneOf.map(rule => cloneRule(rule, refs))
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册