@@ -4,7 +4,7 @@ import {getModuleInfo, setJsonRelativeFiles} from '../util/cacheModuleInfos'
4
4
import { getLibPath , judgeLibPath } from "../util/util"
5
5
import configure from "../configure" ;
6
6
7
- import { getCompPath } from './copyPackageWxComponents'
7
+ import { getCompPath , getRealPackChunks } from './copyPackageWxComponents'
8
8
9
9
10
10
@@ -72,7 +72,14 @@ function getUsedCompPaths(resouce, chunk, jsonRelativeFiles) {
72
72
info . JSXElements . forEach ( element => {
73
73
74
74
if ( ! info . im [ element ] ) {
75
- usedComps [ element ] = `./${ element } `
75
+ // 非import/required组件,有两种情况,1:本文件声明了此组件, 2:组件在其他文件,引入方式非法
76
+ if ( configure . configObj . componentPaths && configure . configObj . componentPaths [ element ] ) {
77
+ const globalPath = configure . configObj . componentPaths [ element ]
78
+ usedComps [ element ] = getGlobalChunkPath ( globalPath , chunk , resouce , jsonRelativeFiles )
79
+ } else {
80
+ // 这里假定所有都是 本文件声明了组件
81
+ usedComps [ element ] = `./${ element } `
82
+ }
76
83
return
77
84
}
78
85
@@ -215,5 +222,46 @@ function shortPath(ao, module) {
215
222
. replace ( extname , '' )
216
223
}
217
224
225
+ function getGlobalChunkPath ( globalPath , chunk , resouce , jsonRelativeFiles ) {
226
+
227
+ let subpageDir = ''
228
+ if ( chunk !== '_rn_' ) {
229
+ subpageDir = chunk . replace ( '/_rn_' , '' )
230
+ resouce = resouce
231
+ . replace ( configure . inputFullpath , configure . inputFullpath + path . sep + subpageDir )
232
+ }
233
+
234
+ let absoluteGlobalPath = null
235
+ if ( judgeLibPath ( globalPath ) ) {
236
+ const libPath = getLibPath ( globalPath )
237
+ jsonRelativeFiles . add ( libPath )
238
+
239
+ const chunks = getRealPackChunks ( libPath )
240
+
241
+ if ( chunks . size === 1 && chunks . has ( '_rn_' ) ) {
242
+ absoluteGlobalPath = path . resolve ( configure . inputFullpath , 'npm' , globalPath )
243
+ } else {
244
+ absoluteGlobalPath = path . resolve ( configure . inputFullpath , subpageDir , 'npm' , globalPath )
245
+ }
246
+ } else {
247
+
248
+ absoluteGlobalPath = path . resolve ( configure . inputFullpath , '.' + globalPath )
249
+
250
+ jsonRelativeFiles . add ( absoluteGlobalPath )
251
+
252
+ const chunks = getModuleInfo ( absoluteGlobalPath ) . chunks
253
+
254
+ if ( chunks . length === 1 && chunks [ 0 ] === '_rn_' ) {
255
+ // do nothing
256
+ } else {
257
+ absoluteGlobalPath = absoluteGlobalPath . replace ( configure . inputFullpath , configure . inputFullpath + path . sep + subpageDir )
258
+ }
259
+ }
260
+
261
+
262
+ return shortPath ( absoluteGlobalPath , resouce )
263
+
264
+ }
265
+
218
266
219
267
0 commit comments