Skip to content
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

请问Dva为什么所有的代码全部都到了 index.js 文件?有分块打包 demo 吗? #427

Closed
xflife opened this issue Dec 23, 2016 · 19 comments
Labels

Comments

@xflife
Copy link

xflife commented Dec 23, 2016

请问Dva为什么所有的代码全部都到了 index.js 文件?有分块打包 demo 吗?

@sorrycc
Copy link
Member

sorrycc commented Dec 23, 2016

@xflife
Copy link
Author

xflife commented Dec 23, 2016

我看了一下,这个打包是到同一个文件,并没有分离开来?

@sorrycc
Copy link
Member

sorrycc commented Dec 23, 2016

@sorrycc sorrycc closed this as completed Dec 24, 2016
@xflife
Copy link
Author

xflife commented Dec 26, 2016

不是按需加载,是分块打包...

@sorrycc
Copy link
Member

sorrycc commented Dec 26, 2016

一个 entry 里要拆包,可以试试 CommonsChunkPlugin

@xflife
Copy link
Author

xflife commented Dec 26, 2016

我写过的 Vue 的项目,Vue 的项目是这样实现的:
路由:
const Login = r => require.ensure([], () => r(require('../components/login/Login.vue')), 'user') export default new Router({ mode: 'history', scrollBehavior: () => ({ y: 0 }), routes: [ { name: 'login', path: '/login', component: Login } ] })
webpack:
output: { path: config.build.assetsRoot, publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath, filename: '[name].js' },
但是在dva里配置这样并不生效

@sorrycc
Copy link
Member

sorrycc commented Dec 26, 2016

这不就是按需加载吗?

@xflife
Copy link
Author

xflife commented Dec 26, 2016

不是,它也实现了分块打包,比如我系统上有二个路由:a,b;
dva 项目中
无论访问 a 还是 b,请求的 index.js;都是包含 a 和 b 的逻辑代码的;
vue 项目中
访问 a 页面,请求的 js 是 a.index.js,访问 b 页面,请求的 js 是 b.index.js。是不相互包含的

@sorrycc
Copy link
Member

sorrycc commented Dec 26, 2016

https://github.com/dvajs/dva/blob/master/examples/dynamic-load/router.js#L6-L27
这段是用来实现你描述的 vue 项目的效果的。

@xflife
Copy link
Author

xflife commented Dec 27, 2016

我有看到这个动态的路由的代码,但是并没有实现 vue 项目中的想过,我现在的代码是这样的
`const Login = c => require.ensure([], require => (
app.model(require('./models/login/loginModel')),
c(null, require('./routes/login/Login'))
));

const Main = c => require.ensure([], require => (
app.model(require('./models/main/mainModel')),
c(null, require('./routes/main/Main'))
));

function interceptPermissions() {
const token = kits.getCookies('tf-token');
const uid = kits.getCookies('tf-uid');
if (!uid || !token) {
app._store.dispatch(routerRedux.replace('/login'))
}
}

return
<Route name="login" path="/(login)"
getComponent={(location, callback) => Login(callback)}/>
<Route name="main" path="/main"
onenter={interceptPermissions()}
getComponent={(location, callback) => Main(callback)}>

<Route path="/main/actives" component={ require('./routes/actives/Actives') } />
<Route path="*" component={ require('./routes/common/Error') }/>

`
并没有实现,无论是run start 还是 build 所有的代码都输出到了一个 index.js 文件

@jiangbo2015
Copy link

jiangbo2015 commented Feb 8, 2017

https://github.com/dvajs/dva-example-user-dashboard/blob/master/src/router.js

@henryzp
Copy link

henryzp commented Mar 23, 2017

mark

2 similar comments
@minzhenyu
Copy link

mark

@DaDaDaDaDaBocai
Copy link

mark

@AlaiNiGuests
Copy link

https://github.com/dvajs/dva/tree/master/examples/dynamic-load
被移走了,按需加载的dva配置我可以从哪里看到?谢谢

@minzhenyu
Copy link

mark

@tcstory
Copy link

tcstory commented Nov 9, 2017

@AlaiNiGuests 你地址里的文档,我看了一下,应该已经不能在dva 2.x以上使用了吧?
那个react-router的语法,是3.x版本的还是4.x版本的?

@ChangerHe
Copy link

mark

@jkhmnk
Copy link

jkhmnk commented Sep 12, 2018

楼主是怎么解决的? 能贴下代码吗? 万分感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants