-
Notifications
You must be signed in to change notification settings - Fork 51
optimize: 支持函数类型的 entry #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
没有给任何参数的话,并没有实际意义吧,可以写自执行函数 |
|
webpack 的 entry 只有是 function 类型时才能动态增减,主要是为了这一点 |
lib/mp-compiler/index.js
Outdated
|
|
||
| const fileInfo = resolveTarget(resourcePath, options.entry) | ||
| const { entry } = options | ||
| const entryObj = typeof entry === 'function' ? entry() : entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entry function 可能返回的是一个 Promise ,这个地方要处理一下
|
可以改成这样? Promise.resolve(entry()).then((result) => {
entryObj = result
}) |
|
emmm 不能用 async 函数好像改动会大一点, |
50d44ef to
1e613c0
Compare
|
可以支持 Promise 了,但是还是会导致 entry 为函数时被多次执行,而且感觉写法不太好,后面我再看看 webpack 的 entry 吧,好像目前是没法直接获得解析后的 entry 对象 |
|
目前功能上应该问题不大,最好还是能在重构时通过配置信息判断页面类型之类的信息,避免直接使用 entry 对象 |
|
在 webpack 的 DynamicEntryPlugin 这个插件里直接把解析后的 |
|
webpack 那边的人说可以直接通过 |
目前这样修改可以支持函数类型的 entry,但是会多执行一次 options.entry 这个函数,这个函数本身没有副作用的话是没问题的,不是很了解 webpack 本身是怎么处理函数类型的 entry 的,有比较了解的可以指点下