Skip to content

Commit 50d44ef

Browse files
author
F-loat
committed
optimize: 支持函数类型的 entry
1 parent 9f157b6 commit 50d44ef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/mp-compiler/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ function compileMPScript (script, mpOptioins, moduleId) {
148148
components.isCompleted = true
149149
}
150150

151-
const fileInfo = resolveTarget(this.resourcePath, this.options.entry)
151+
const { entry } = this.options
152+
const entryObj = typeof entry === 'function' ? entry() : entry
153+
const fileInfo = resolveTarget(this.resourcePath, entryObj)
152154
cacheFileInfo(this.resourcePath, fileInfo, { importsMap, components, moduleId })
153155

154156
return script
@@ -168,7 +170,9 @@ function compileMP (content, mpOptioins) {
168170
// metadata: config
169171
const { config, rootComponent } = metadata
170172

171-
const fileInfo = resolveTarget(resourcePath, options.entry)
173+
const { entry } = options
174+
const entryObj = typeof entry === 'function' ? entry() : entry
175+
const fileInfo = resolveTarget(resourcePath, entryObj)
172176
cacheFileInfo(resourcePath, fileInfo)
173177
const { src, name, isApp, isPage } = fileInfo
174178

@@ -179,7 +183,7 @@ function compileMP (content, mpOptioins) {
179183

180184
// 只有 app 才处理 pages
181185
if (isApp) {
182-
const pages = Object.keys(options.entry).concat(configObj.pages).filter(v => v && v !== 'app').map(getPageSrc)
186+
const pages = Object.keys(entryObj).concat(configObj.pages).filter(v => v && v !== 'app').map(getPageSrc)
183187

184188
// ^ 开头的放在第一个
185189
const startPageIndex = pages.findIndex(v => startPageReg.test(v))

0 commit comments

Comments
 (0)