Skip to content

Commit 055881b

Browse files
authored
Merge branch 'master' into fix-rn-view-linear
2 parents de2990f + 15f127f commit 055881b

File tree

6 files changed

+80
-8
lines changed

6 files changed

+80
-8
lines changed

packages/webpack-plugin/lib/resolver/AddModePlugin.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,31 @@ module.exports = class AddModePlugin {
3939

4040
const queryObj = parseQuery(request.query || '?')
4141
const queryInfix = queryObj.infix
42-
if (!implicitMode) queryObj.mode = mode
43-
queryObj.infix = `${queryInfix || ''}.${mode}`
4442

4543
// 如果已经确认是mode后缀的文件,添加query与mode后直接返回
4644
if (modePattern.test(path.basename(resourcePath))) {
47-
request.query = stringifyQuery(queryObj)
48-
request.mode = obj.mode
45+
// 已经被resolved到对应mode的文件,避免重复添加mode
46+
const isResolved = (implicitMode || queryObj.mode === mode) && modePattern.test(queryObj.infix)
47+
if (!isResolved) {
48+
queryObj.infix = `${queryInfix || ''}.${mode}`
49+
if (!implicitMode) queryObj.mode = mode
50+
request.query = stringifyQuery(queryObj)
51+
request.mode = obj.mode
52+
}
4953
return callback()
5054
} else if (defaultMode && defaultModePattern.test(path.basename(resourcePath))) {
51-
queryObj.infix = `${queryInfix || ''}.${defaultMode}`
52-
request.query = stringifyQuery(queryObj)
53-
request.mode = obj.mode
55+
const isResolved = (implicitMode || queryObj.mode === mode) && defaultModePattern.test(queryObj.infix)
56+
if (!isResolved) {
57+
queryObj.infix = `${queryInfix || ''}.${defaultMode}`
58+
if (!implicitMode) queryObj.mode = mode
59+
request.query = stringifyQuery(queryObj)
60+
request.mode = obj.mode
61+
}
5462
return callback()
5563
}
5664

65+
if (!implicitMode) queryObj.mode = mode
66+
queryObj.infix = `${queryInfix || ''}.${mode}`
5767
obj.query = stringifyQuery(queryObj)
5868
obj.path = addInfix(resourcePath, mode, extname)
5969
obj.relativePath = request.relativePath && addInfix(request.relativePath, mode, extname)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<view> ali </view>
3+
</template>
4+
5+
<script>
6+
import { createComponent } from '@mpxjs/core'
7+
8+
createComponent({})
9+
</script>
10+
11+
<script type="application/json">
12+
{
13+
"component": true
14+
}
15+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<view> ali </view>
3+
</template>
4+
5+
<script>
6+
import { createComponent } from '@mpxjs/core'
7+
8+
createComponent({})
9+
</script>
10+
11+
<script type="application/json">
12+
{
13+
"component": true
14+
}
15+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<view> ali </view>
3+
</template>
4+
5+
<script>
6+
import { createComponent } from '@mpxjs/core'
7+
8+
createComponent({})
9+
</script>
10+
11+
<script type="application/json">
12+
{
13+
"component": true
14+
}
15+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<view> wx </view>
3+
</template>
4+
5+
<script>
6+
import { createComponent } from '@mpxjs/core'
7+
8+
createComponent({})
9+
</script>
10+
11+
<script type="application/json">
12+
{
13+
"component": true
14+
}
15+
</script>

test/e2e/miniprogram-project/src/pages/index.mpx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<view>
33
<list></list>
44
<customOutputComp></customOutputComp>
5+
<mode></mode>
56
</view>
67
</template>
78

@@ -17,7 +18,8 @@
1718
{
1819
"usingComponents": {
1920
"list": "../components/list",
20-
"customOutputComp": "../components/customOutputCom.mpx"
21+
"customOutputComp": "../components/customOutputCom.mpx",
22+
"mode": "../components/mode",
2123
}
2224
}
2325
</script>

0 commit comments

Comments
 (0)