3
我無法重新創建將React組件拆分爲單獨的文件,例如0.js
,1.js
,2.js
等,用於代碼拆分並減少bundle.js文件。有人碰巧知道如何產生這個結果嗎?我試圖用ChunkManifest
和webpack-manifest
插件重新創建它,但它不會這樣做。任何建議都會很棒!Webpack將React組件拆分爲「0.js」「1.js」等。etc
routes.js
function errorLoading(err) {
console.error('Dynamic page loading failed', err);
}
function loadRoute(cb) {
return (module) => cb(null, module.default);
}
export default [
{
path: '/',
component: App,
childRoutes: [
{
path: 'signup',
getComponent(location, cb) {
System.import('./modules/App/components/Authentication/Login.js')
.then(loadRoute(cb))
.catch(errorLoading);
}
},
{
path: 'verify',
getComponent(location, cb) {
System.import('./modules/App/components/Authentication/Verify.js')
.then(loadRoute(cb))
.catch(errorLoading);
}
},
{
path: 'password-reset',
getComponent(location, cb) {
System.import('./modules/App/components/Authentication/PasswordReset.js')
.then(loadRoute(cb))
.catch(errorLoading);
}
},
{
path: 'new-password',
getComponent(location, cb) {
System.import('./modules/App/components/Authentication/NewPassword.js')
.then(loadRoute(cb))
.catch(errorLoading);
}
}
]
}
]
真棒!我會看看這個鏈接'https:// github.com/ReactTraining/react-router/blob/master/examples/huge-apps'並且回覆你:) – Clement
我跟着鏈接https:// github .com/ReactTraining/react-router/blob/master/expleples/huge-apps',它工作正常! :) – Clement
上一個鏈接是壞的,只是谷歌「巨大的應用程序reactjs」,我發現這個:(它包含一個原始鏈接副本)https://github.com/echenley/react-router-huge-apps-refactor – pdem