Skip to content

Conversation

@F-loat
Copy link
Member

@F-loat F-loat commented Apr 29, 2018

目前这样修改可以支持函数类型的 entry,但是会多执行一次 options.entry 这个函数,这个函数本身没有副作用的话是没问题的,不是很了解 webpack 本身是怎么处理函数类型的 entry 的,有比较了解的可以指点下

@steinslin
Copy link
Member

没有给任何参数的话,并没有实际意义吧,可以写自执行函数

@F-loat
Copy link
Member Author

F-loat commented Apr 30, 2018

webpack 的 entry 只有是 function 类型时才能动态增减,主要是为了这一点


const fileInfo = resolveTarget(resourcePath, options.entry)
const { entry } = options
const entryObj = typeof entry === 'function' ? entry() : entry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry function 可能返回的是一个 Promise ,这个地方要处理一下

@F-loat
Copy link
Member Author

F-loat commented May 4, 2018

可以改成这样?

Promise.resolve(entry()).then((result) => {
  entryObj = result
})

@F-loat
Copy link
Member Author

F-loat commented May 4, 2018

emmm 不能用 async 函数好像改动会大一点,

@F-loat F-loat force-pushed the support-function-entry branch from 50d44ef to 1e613c0 Compare May 9, 2018 09:35
@F-loat
Copy link
Member Author

F-loat commented May 9, 2018

可以支持 Promise 了,但是还是会导致 entry 为函数时被多次执行,而且感觉写法不太好,后面我再看看 webpack 的 entry 吧,好像目前是没法直接获得解析后的 entry 对象

@F-loat
Copy link
Member Author

F-loat commented May 18, 2018

目前功能上应该问题不大,最好还是能在重构时通过配置信息判断页面类型之类的信息,避免直接使用 entry 对象

@F-loat
Copy link
Member Author

F-loat commented May 18, 2018

在 webpack 的 DynamicEntryPlugin 这个插件里直接把解析后的 entries 加到 compilation 对象中之后就可以通过 this._compilation 获取到了,所以应该是可以直接拿到解析后的 entry 的,我再找找目前有没有在哪个属性里存着。。

@F-loat
Copy link
Member Author

F-loat commented May 19, 2018

webpack 那边的人说可以直接通过 compilation.entrypoints[..].entryModule,但是我试了下在 loader 里 entrypoints 一直是个空对象,mpvue-entry 这个库加了个 plugin 通过对 entry 进行 hack 来实现支持,目前新增页面已经可以热更新,这个 pr 就先关闭了

@F-loat F-loat closed this May 19, 2018
@F-loat F-loat deleted the support-function-entry branch May 19, 2018 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants