-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: support mpa loader #3594
feat: support mpa loader #3594
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getOptions } from 'loader-utils'; | ||
|
||
function mpaLoader() { | ||
const options = getOptions(this) || {}; | ||
const framework = options.framework || 'rax'; | ||
const withSSR = process.env.__SSR_ENABLED__ === 'true'; | ||
let appRender = ''; | ||
if (options.type === 'weex') { | ||
appRender = 'render(createElement(Entry), null, { driver: DriverUniversal });'; | ||
} else { | ||
appRender = ` | ||
const renderApp = async function() { | ||
// process App.getInitialProps | ||
if (withSSR && window.__INITIAL_DATA__ && window.__INITIAL_DATA__.pageData !== null) { | ||
Object.assign(comProps, window.__INITIAL_DATA__.pageData); | ||
} else if (Component.getInitialProps) { | ||
Object.assign(comProps, await Component.getInitialProps()); | ||
} | ||
render(createElement(Entry), document.getElementById("root"), { driver: DriverUniversal, hydrate: withSSR }); | ||
} | ||
|
||
renderApp(); | ||
`; | ||
} | ||
const source = ` | ||
import { render, createElement } from '${framework}'; | ||
import Component from '${process.platform === 'win32' ? this.resourcePath.replace(/\//g, '\\\\') : this.resourcePath}'; | ||
import DriverUniversal from 'driver-universal'; | ||
const withSSR = ${withSSR}; | ||
|
||
const comProps = {}; | ||
|
||
function Entry() { | ||
return createElement(Component, comProps); | ||
} | ||
${appRender} | ||
`; | ||
return source; | ||
} | ||
|
||
export default mpaLoader; |
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.
!== null
可以去掉 ?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.
pageData 返回值为 null / object,暂不修改