React lazy does not cause splitting bundle in chunks











up vote
1
down vote

favorite












As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.



Here's my implementation:



import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';

const AppItemComponent = React.lazy(() => import('../AppItem'));

class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;

getApps(3);
}

renderAppItem = () => {
const { apps } = this.props;

return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};

render() {
const { apps } = this.props;

return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}

const mapStateToProps = ({ apps }) => {
return { apps };
};

const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};

export default connect(mapStateToProps, mapDispatchToProps)(Apps);


I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.



What am I missing here?










share|improve this question




















  • 1




    Maybe you are importing it like e.g. import AppItem from '../../AppItem'; somewhere else in the code?
    – Tholle
    Nov 7 at 9:40












  • Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
    – Barth
    Nov 7 at 9:46






  • 1




    I don't see why that should happen from the code currently in your question, but let's say you imported a component Home in your Apps file, and Home imported AppItem, then that would prevent it from being code split into a separate bundle.
    – Tholle
    Nov 7 at 9:49










  • You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
    – Barth
    Nov 7 at 10:30















up vote
1
down vote

favorite












As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.



Here's my implementation:



import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';

const AppItemComponent = React.lazy(() => import('../AppItem'));

class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;

getApps(3);
}

renderAppItem = () => {
const { apps } = this.props;

return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};

render() {
const { apps } = this.props;

return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}

const mapStateToProps = ({ apps }) => {
return { apps };
};

const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};

export default connect(mapStateToProps, mapDispatchToProps)(Apps);


I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.



What am I missing here?










share|improve this question




















  • 1




    Maybe you are importing it like e.g. import AppItem from '../../AppItem'; somewhere else in the code?
    – Tholle
    Nov 7 at 9:40












  • Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
    – Barth
    Nov 7 at 9:46






  • 1




    I don't see why that should happen from the code currently in your question, but let's say you imported a component Home in your Apps file, and Home imported AppItem, then that would prevent it from being code split into a separate bundle.
    – Tholle
    Nov 7 at 9:49










  • You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
    – Barth
    Nov 7 at 10:30













up vote
1
down vote

favorite









up vote
1
down vote

favorite











As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.



Here's my implementation:



import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';

const AppItemComponent = React.lazy(() => import('../AppItem'));

class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;

getApps(3);
}

renderAppItem = () => {
const { apps } = this.props;

return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};

render() {
const { apps } = this.props;

return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}

const mapStateToProps = ({ apps }) => {
return { apps };
};

const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};

export default connect(mapStateToProps, mapDispatchToProps)(Apps);


I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.



What am I missing here?










share|improve this question















As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.



Here's my implementation:



import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';

const AppItemComponent = React.lazy(() => import('../AppItem'));

class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;

getApps(3);
}

renderAppItem = () => {
const { apps } = this.props;

return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};

render() {
const { apps } = this.props;

return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}

const mapStateToProps = ({ apps }) => {
return { apps };
};

const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};

export default connect(mapStateToProps, mapDispatchToProps)(Apps);


I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.



What am I missing here?







reactjs lazy-loading






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 9:30









Nguyễn Thanh Tú

4,480827




4,480827










asked Nov 7 at 9:25









Barth

256110




256110








  • 1




    Maybe you are importing it like e.g. import AppItem from '../../AppItem'; somewhere else in the code?
    – Tholle
    Nov 7 at 9:40












  • Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
    – Barth
    Nov 7 at 9:46






  • 1




    I don't see why that should happen from the code currently in your question, but let's say you imported a component Home in your Apps file, and Home imported AppItem, then that would prevent it from being code split into a separate bundle.
    – Tholle
    Nov 7 at 9:49










  • You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
    – Barth
    Nov 7 at 10:30














  • 1




    Maybe you are importing it like e.g. import AppItem from '../../AppItem'; somewhere else in the code?
    – Tholle
    Nov 7 at 9:40












  • Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
    – Barth
    Nov 7 at 9:46






  • 1




    I don't see why that should happen from the code currently in your question, but let's say you imported a component Home in your Apps file, and Home imported AppItem, then that would prevent it from being code split into a separate bundle.
    – Tholle
    Nov 7 at 9:49










  • You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
    – Barth
    Nov 7 at 10:30








1




1




Maybe you are importing it like e.g. import AppItem from '../../AppItem'; somewhere else in the code?
– Tholle
Nov 7 at 9:40






Maybe you are importing it like e.g. import AppItem from '../../AppItem'; somewhere else in the code?
– Tholle
Nov 7 at 9:40














Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46




Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46




1




1




I don't see why that should happen from the code currently in your question, but let's say you imported a component Home in your Apps file, and Home imported AppItem, then that would prevent it from being code split into a separate bundle.
– Tholle
Nov 7 at 9:49




I don't see why that should happen from the code currently in your question, but let's say you imported a component Home in your Apps file, and Home imported AppItem, then that would prevent it from being code split into a separate bundle.
– Tholle
Nov 7 at 9:49












You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30




You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186595%2freact-lazy-does-not-cause-splitting-bundle-in-chunks%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186595%2freact-lazy-does-not-cause-splitting-bundle-in-chunks%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini