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
Webpack 2 Dynamic Import degrades build performance (slow) compared to static imports. #4636
Comments
As a side note, I couldn't find an exact replica issue for this bug. #4582 seems to be a similar problem? |
Temporary workaround we found: import { ImportLoadable } from '../';
let Account;
let AccountContainer;
let AddCard;
let EditCard;
let DeleteCard;
let CardForm;
let Cards;
let Card;
let Charges;
let Charge;
let Invoices;
let Invoice;
let PurchaseMap;
let PurchasePlan;
if(process.env.NODE_ENV == 'production') {
Account = ImportLoadable(f => import('./account'));
AccountContainer = ImportLoadable(f => import('./accountContainer'));
AddCard = ImportLoadable(f => import('./addCard'));
EditCard = ImportLoadable(f => import('./editCard'));
DeleteCard = ImportLoadable(f => import('./deleteCard'));
CardForm = ImportLoadable(f => import('./cardForm'));
Cards = ImportLoadable(f => import('./cards'));
Card = ImportLoadable(f => import('./card'));
Charges = ImportLoadable(f => import('./charges'));
Charge = ImportLoadable(f => import('./charge'));
Invoices = ImportLoadable(f => import('./invoices'));
Invoice = ImportLoadable(f => import('./invoice'));
PurchaseMap = ImportLoadable(f => import('./purchaseMap'));
PurchasePlan = ImportLoadable(f => import('./purchasePlan'));
}
else {
Account = require('./account');
AccountContainer = require('./accountContainer');
AddCard = require('./addCard');
EditCard = require('./editCard');
DeleteCard = require('./deleteCard');
CardForm = require('./cardForm');
Cards = require('./cards');
Card = require('./card');
Charges = require('./charges');
Charge = require('./charge');
Invoices = require('./invoices');
Invoice = require('./invoice');
PurchaseMap = require('./purchaseMap');
PurchasePlan = require('./purchasePlan');
}
export {
Account,
AccountContainer,
AddCard,
EditCard,
DeleteCard,
CardForm,
Cards,
Card,
Charges,
Charge,
Invoices,
Invoice,
PurchaseMap,
PurchasePlan
} UDPATE: ^^^This actually did not work. |
do you have a repo for profiling? |
I have this too. ~50 chunks with Does it mean that each entrypoint results in a fresh evaluation of its dependency tree? |
I have a shallow understanding of webpack, so I'm unsure. I would make a pull request with the change if I can be pointed in the right direction to fix the issue. |
I've tried this syntax and it's much better:
|
do you have a repo for profiling? |
Related to #4716 |
@Vanuan a temporary workaround I've used is to strip out |
@peterdotjs looks like babel-plugin-remove-webpack does not in-fact remove webpack 2 dynamic import syntax. See docs |
@NomadGraphix I was referring specifically to |
I'm facing this issue too, converting a lot of |
I've created a small repo to help reproduce the problem here. Just clone and
The repo and the files included are very small so the difference is not that big but if you modify a random file it's usually taking ~300/400ms to rebuild with Also if you edit a file with
versus this using
|
From a brief chat with @sokra, my impression that #4636 (comment) does not actually demonstrate a perf regression, but rather the difference in how With With So
Apparently the |
Thanks for the insight @gaearon , I thought that using |
@gaearon, this makes quite a bit of sense. My though for a solution is to have an option that allows us to disable dynamic We are willing to have a longer build time for pushing to production, but it is debilitating for development. |
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
is this applicable for latest versions as well ? Please suggest better solution to do so |
Do you want to request a feature or report a bug?
I would like to report a bug.
What is the current behavior?
When converting my project's components to dynamically import components instead of using static import statements, the build time increases by 10x and incremental builds by about the same.
The dynamic import functionality has reduced my bundle size astronomically by breaking all of my react components into separate chunks that get loaded into the app on-demand. I used a react-loader setup to replace most of my component static imports with dynamic imports.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
I expect the dynamic import build time to be the same as a static import build time.
If this is a feature request, what is motivation or use case for changing the behavior?
It seems that even though the dynamic import automatically chunks your bundle into multiple files, that when changing the underlying code for one of those chunks, webpack should be able to detect which file that was and only rebuild that file and hot-reload it.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
Webpack 2.3.2
Webpack-Dev-Server 2.4.2
The text was updated successfully, but these errors were encountered: