-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
打包后文件太大怎么办 #675
Comments
|
@sorrycc 我是还要安装什么东西吗? 通过浏览器看,有很多依赖的js都打包进去了 |
|
@sorrycc 大神,我看不懂。。。 附上我的package.json文件 |
@sorrycc 分析了下 是引用了moment导致文件这么大,怎么样才能解决这个问题啊 |
参考这个给 moment 加 noParse 试试。 |
@liuxingling 你是怎么打包成多个js文件的啊?我每次打包都是一个index.js 文件 |
@iceshu 用require.ensure,参见这里:https://github.com/dvajs/dva-example-user-dashboard/blob/master/src/router.js#L18 |
@xufei 多谢啊~ 还有个问题啊 弱弱的问句就是打包出来的时候是1.1.js 2.2.js 更换这些名字是在哪配置的啊,我用的是roadhog |
@iceshu 哥们,你好,我也遇到跟你一样的问题,打包后实际文件大于打包时输出的大小,请问你是怎么解决的啊,能不能分享解决的方法啊,我按照上面给的方法,通过require.ensure 去加载,但是没有任何效果 |
@K-walker 可以的啊 const rootRoute = [
{
path: '/',
indexRoute: {onEnter: (nextState, replace) => replace('home')},
component: require('./routes/home/pages/index'),
getChildRoutes(partialNextState, cb) {
require.ensure([], (require) => {
cb(null, [
require('./routes/home/router')(app),
require('./routes/competing/router')(app),
require('./routes/buynum/router')(app),
require('./routes/myinfo/router')(app),
{
path: 'login',
getComponent(nextState, cb) {
registerModel(app, require('./models/pages/login'));
require.ensure([], (require) => {
cb(null, require('./routes/myinfo/pages/login'))
}, 'login')
}
},
{
path: 'register',
getComponent(nextState, cb) {
registerModel(app, require('./models/pages/register'));
require.ensure([], (require) => {
cb(null, require('./routes/myinfo/pages/register'))
}, 'register')
}
}, {
path: 'getpwd',
getComponent(nextState, cb) {
require.ensure([], (require) => {
registerModel(app, require('./models/pages/myinfo-security'));
cb(null, require('./routes/myinfo/pages/getpwd'))
}, 'getpwd')
}
},
{
path: '*',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('./routes/myinfo/pages/pagenotfound'))
}, 'getpwd')
}
}
]);
});
},
}
];
return <Router history={history} routes={rootRoute}/>; 自路由home export default (app)=> ({
path: 'home',
component: require('../../routes/home/pages/index'),
indexRoute: {onEnter: (nextState, replace) => replace('home/index')},
getChildRoutes(partialNextState, cb) {
require.ensure([], (require) => {
registerModel(app, require('../../models/home/home'));
registerModel(app, require('../../models/home/lotterys'));
cb(null, [
{
path: 'index',
component: require('./pages/home'),
},
{
path: 'listshow',
component: require('./pages/listshow'),
},
{
path: 'listshowinfo',
component: require('./pages/listsshowinfo'),
},
{
path: 'lotterylist',
component: require('./pages/lotterylist'),
},
{
path: 'zxlists',
component: require('./pages/zxlists'),
},
{
path: 'zxinfo',
component: require('./pages/zxinfo'),
}
]);
});
},
}); |
多谢,好像是减小了包的大小,还有个问题,不知道能不能请教下如何不把 antd.css 打进去,因为这个样式属于官方的,我其实不用对其修改的,我只要放在本地就可以了,然后引用,但是如果打包进去也会占用包的大小,再比如jquery,如果用到了话,我也可以不用将其打包,放在本地引用,这样就减小了包的大小,我只需要打包我写的jsx文件即可,不知道有没有这样的方法! |
@iceshu 你好,请问你知道更换文件名是在哪里配置了吗 |
@K-walker .roadhogrc.js 里配置externals 例子大概是这样 |
@shuxiaotai require.ensure([], (require) => { |
这是我的roadhog文件,打包出来后的文件平均八百多kb,太大了啊,求指教
The text was updated successfully, but these errors were encountered: