@@ -155,6 +155,10 @@ function compileMP (content, mpOptioins) {
155155 const fileInfo = resolveTarget ( resourcePath , options . entry )
156156 cacheFileInfo ( resourcePath , fileInfo )
157157 const { src, name, isApp, isPage } = fileInfo
158+ if ( isApp ) {
159+ // 解析前将可能存在的全局组件清空
160+ clearGlobalComponents ( )
161+ }
158162
159163 const babelrc = getBabelrc ( mpOptioins . globalBabelrc )
160164 // app入口进行全局component解析
@@ -166,11 +170,18 @@ function compileMP (content, mpOptioins) {
166170 if ( isApp ) {
167171 // 保存旧数据,用于对比
168172 const oldGlobalComponents = globalComponents
169- // 开始解析app入口文件时把全局组件清空 ,解析完成后再进行赋值,标志全局组件解析完成
173+ // 开始解析组件路径时把全局组件清空 ,解析完成后再进行赋值,标志全局组件解析完成
170174 globalComponents = null
171- clearGlobalComponents ( )
172175
173- const handleResult = ( ) => {
176+ // 解析全局组件的路径
177+ const components = { }
178+ resolveSrc ( globalComps , components , resolve , context ) . then ( ( ) => {
179+ handleResult ( components )
180+ } ) . catch ( err => {
181+ console . error ( err )
182+ handleResult ( components )
183+ } )
184+ const handleResult = components => {
174185 globalComponents = components
175186 // 热更时,如果全局组件更新,需要重新生成所有的wxml
176187 if ( oldGlobalComponents && ! deepEqual ( oldGlobalComponents , globalComponents ) ) {
@@ -184,15 +195,6 @@ function compileMP (content, mpOptioins) {
184195 } )
185196 }
186197 }
187-
188- // 解析全局组件的路径
189- const components = { }
190- resolveSrc ( globalComps , components , resolve , context ) . then ( ( ) => {
191- handleResult ( )
192- } ) . catch ( err => {
193- console . error ( err )
194- handleResult ( )
195- } )
196198 }
197199
198200 if ( isApp || isPage ) {
0 commit comments