@@ -155,6 +155,10 @@ function compileMP (content, mpOptioins) {
155
155
const fileInfo = resolveTarget ( resourcePath , options . entry )
156
156
cacheFileInfo ( resourcePath , fileInfo )
157
157
const { src, name, isApp, isPage } = fileInfo
158
+ if ( isApp ) {
159
+ // 解析前将可能存在的全局组件清空
160
+ clearGlobalComponents ( )
161
+ }
158
162
159
163
const babelrc = getBabelrc ( mpOptioins . globalBabelrc )
160
164
// app入口进行全局component解析
@@ -166,11 +170,18 @@ function compileMP (content, mpOptioins) {
166
170
if ( isApp ) {
167
171
// 保存旧数据,用于对比
168
172
const oldGlobalComponents = globalComponents
169
- // 开始解析app入口文件时把全局组件清空 ,解析完成后再进行赋值,标志全局组件解析完成
173
+ // 开始解析组件路径时把全局组件清空 ,解析完成后再进行赋值,标志全局组件解析完成
170
174
globalComponents = null
171
- clearGlobalComponents ( )
172
175
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 => {
174
185
globalComponents = components
175
186
// 热更时,如果全局组件更新,需要重新生成所有的wxml
176
187
if ( oldGlobalComponents && ! deepEqual ( oldGlobalComponents , globalComponents ) ) {
@@ -184,15 +195,6 @@ function compileMP (content, mpOptioins) {
184
195
} )
185
196
}
186
197
}
187
-
188
- // 解析全局组件的路径
189
- const components = { }
190
- resolveSrc ( globalComps , components , resolve , context ) . then ( ( ) => {
191
- handleResult ( )
192
- } ) . catch ( err => {
193
- console . error ( err )
194
- handleResult ( )
195
- } )
196
198
}
197
199
198
200
if ( isApp || isPage ) {
0 commit comments