-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Bundle size #427
Comments
Hi @ritz078. Nice to hear from you! 😄 That is a sweet looking breakdown. Help me better understand what it means though. For example, why does it show the That should slim the module down a bit more for you as it wouldn't pull in any of the HOCs besides |
Yes you are right. it should have taken files from cc @TheLarkInn Can any error in configuration cause this error where the files are not taken from webpack 2.1.0-beta.25 |
Only latest webpack pulls from the "module" field not jsnext:main. Otherwise you have to specify a seperate field in your config under resolver.modules |
You could also import from import { List } from 'react-virtualized/dist/es'; |
@bvaughn I guess that means "module" works for webpack 2 and "jsnext:main" for rollup. |
Oh I see! Seems related to webpack/webpack/issues/1979 I don't mind doing a quick bugfix release to add the "module" attribute to |
was going through that PR only. Seems like even rollup is now supporting 'module'. |
@ritz078 give version 8.0.12 a quick try and let me know if the results are improved for you. Also, thanks for the quick reply @TheLarkInn! Very helpful. |
Yeah, looks like I wasn't following along closely enough with the new lookup rules |
Ok. That's looking better in terms of My next question would be- why do |
yes that's my doubt too. the code is simply import { InfiniteLoader, AutoSizer, List } from 'react-virtualized' |
So it seems that tree shaking isn't working. If I change the above code to import { InfiniteLoader } from 'react-virtualized/dist/es/InfiniteLoader'
import { AutoSizer } from 'react-virtualized/dist/es/AutoSizer'
import { List } from 'react-virtualized/dist/es/List' file size change significantly. huge win this way. cc: @TheLarkInn |
Maybe my That graph does indeed look much more reasonable. Shouldn't you be able to at least change your imports to... import { InfiniteLoader } from 'react-virtualized/InfiniteLoader'
import { AutoSizer } from 'react-virtualized/AutoSizer'
import { List } from 'react-virtualized/List' ...given the module lookup rules? |
Its not working that way. Even individually picking |
Could you elaborate a bit more @ritz078? What wasn't working about the es build? |
Here are all the cases that I tried Case I import {InfiniteLoader, AutoSizer, List} from 'react-virtualized' Build: ✅ Case II import { InfiniteLoader } from 'react-virtualized/InfiniteLoader'
import { AutoSizer } from 'react-virtualized/AutoSizer'
import { List } from 'react-virtualized/List' Build: ❌ can't resolve modules Case III import { InfiniteLoader } from 'react-virtualized/dist/es/InfiniteLoader'
import { AutoSizer } from 'react-virtualized/dist/es/AutoSizer'
import { List } from 'react-virtualized/dist/es/List' Build: ✅ Case IV import { InfiniteLoader } from 'react-virtualized/dist/commonjs/InfiniteLoader'
import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer'
import { List } from 'react-virtualized/dist/commonjs/List' Build: ✅ So currently we are using this. Hopefully we will be able to figure out the webpack issue soon. |
I see. The error you mentioned ("Unhandled Promise rejection: SyntaxError: Unexpected token import") sounds like Webpack is configured not to transpile modules within the |
Hopefully we will be able to figure that out soon. Closing this issue. Thanks for the help. |
Any time @ritz078! Please share any additional findings if you think of it. 😁 |
Surely. |
Ran into the same exact issue. Webpack 2 and tree-shaking did not work until: // Changing...
import { AutoSizer, Column, Table, InfiniteLoader } from 'react-virtualized';
// To...
import { InfiniteLoader } from 'react-virtualized/dist/es/InfiniteLoader';
import { AutoSizer } from 'react-virtualized/dist/es/AutoSizer';
import { Column, Table } from 'react-virtualized/dist/es/Table'; 👍 |
thanks for the solutions, works for my setup
|
Same, halved the size of my |
I've done some investigation on this same problem today.
Take a look at webpack output for my project (without mangling and keeping the comments): /* exports provided: ArrowKeyStepper, AutoSizer, CellMeasurer, CellMeasurerCache, Collection, ColumnSizer, accessibilityOverscanIndicesGetter, defaultCellRangeRenderer, defaultOverscanIndicesGetter, Grid, InfiniteLoader, List, createMasonryCellPositioner, Masonry, MultiGrid, ScrollSync, defaultTableCellDataGetter, defaultTableCellRenderer, defaultTableHeaderRenderer, defaultTableHeaderRowRenderer, defaultTableRowRenderer, Table, Column, SortDirection, SortIndicator, WindowScroller */
/* exports used: CellMeasurerCache, CellMeasurer, AutoSizer, InfiniteLoader, List */
/*!**********************************************!*\
!*** ./~/react-virtualized/dist/es/index.js ***!
\**********************************************/
/***/
function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */
var __WEBPACK_IMPORTED_MODULE_1__AutoSizer__ = (__webpack_require__(/*! ./ArrowKeyStepper */ 847),
__webpack_require__(/*! ./AutoSizer */ 848));
/* harmony reexport (binding) */
__webpack_require__.d(__webpack_exports__, "c", function() {
return __WEBPACK_IMPORTED_MODULE_1__AutoSizer__.a;
});
/* harmony import */
var __WEBPACK_IMPORTED_MODULE_2__CellMeasurer__ = __webpack_require__(/*! ./CellMeasurer */ 353);
/* harmony reexport (binding) */
__webpack_require__.d(__webpack_exports__, "b", function() {
return __WEBPACK_IMPORTED_MODULE_2__CellMeasurer__.a;
}), /* harmony reexport (binding) */
__webpack_require__.d(__webpack_exports__, "a", function() {
return __WEBPACK_IMPORTED_MODULE_2__CellMeasurer__.b;
});
/* harmony import */
var __WEBPACK_IMPORTED_MODULE_6__InfiniteLoader__ = (__webpack_require__(/*! ./Collection */ 853),
__webpack_require__(/*! ./ColumnSizer */ 855), __webpack_require__(/*! ./Grid */ 147),
__webpack_require__(/*! ./InfiniteLoader */ 861));
/* harmony reexport (binding) */
__webpack_require__.d(__webpack_exports__, "d", function() {
return __WEBPACK_IMPORTED_MODULE_6__InfiniteLoader__.a;
});
/* harmony import */
var __WEBPACK_IMPORTED_MODULE_7__List__ = __webpack_require__(/*! ./List */ 862);
/* harmony reexport (binding) */
__webpack_require__.d(__webpack_exports__, "e", function() {
return __WEBPACK_IMPORTED_MODULE_7__List__.a;
});
/* harmony import */
__webpack_require__(/*! ./Masonry */ 865), __webpack_require__(/*! ./MultiGrid */ 867),
__webpack_require__(/*! ./ScrollSync */ 868), __webpack_require__(/*! ./Table */ 869),
__webpack_require__(/*! ./WindowScroller */ 870);
}, /* 873 */ The comments on the first 2 lines shows exactly that tree shaking algorithm is working, and you can see at the end of the module that the harmony imports of the unused modules are still there, but no exports. I tried removing My conclusion is that this is actually a webpack issue or an unimplemented feature. For now it's better to use direct imports like Right now I'm trying to find something related on webpack issues. |
@TheLarkInn any chance you could weigh in on where the issue should be corrected; webpack / library The issue with the es index.js file's export syntax doesn't seem to allow for tree shaking export { ArrowKeyStepper } from "./ArrowKeyStepper";
export { AutoSizer } from "./AutoSizer";
export { CellMeasurer, CellMeasurerCache } from "./CellMeasurer";
export { Collection } from "./Collection";
export { ColumnSizer } from "./ColumnSizer";
export { accessibilityOverscanIndicesGetter, defaultCellRangeRenderer, defaultOverscanIndicesGetter, Grid } from "./Grid";
export { InfiniteLoader } from "./InfiniteLoader";
export { List } from "./List";
export { createCellPositioner as createMasonryCellPositioner, Masonry } from "./Masonry";
export { MultiGrid } from "./MultiGrid";
export { ScrollSync } from "./ScrollSync";
export { defaultCellDataGetter as defaultTableCellDataGetter, defaultCellRenderer as defaultTableCellRenderer, defaultHeaderRenderer as defaultTableHeaderRenderer, defaultHeaderRowRenderer as defaultTableHeaderRowRenderer, defaultRowRenderer as defaultTableRowRenderer, Table, Column, SortDirection, SortIndicator } from "./Table";
export { WindowScroller } from "./WindowScroller"; |
@drKnoxy The problem is untreeshakable classes which are transpilled to function constructor with prototype. It's side effect for bundlers. All component based libraries affected by this. Just use paths like |
Doesn't that sound really lame though? Feels feature incomplete... for
either treeshaking / import syntax / uglify
…On Mon, Oct 2, 2017, 3:53 PM Bogdan Chadkin ***@***.***> wrote:
@drKnoxy <https://github.com/drknoxy> The problem is untreeshakable
classes which are transpilled to function constructor with prototype. It's
side effect for bundlers. All component based libraries affected by this.
Just use paths like import AutoSizer from
'react-virtualized/dist/es/AutoSizer';. In the future side-effects field
may fix this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#427 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAk3b-9GJiP9XZE0W2cfW66uDc7ypVwlks5soT8bgaJpZM4KRTvr>
.
|
It works, but it's not panacea. Static analyzing is hard when you deal with javascript. |
@TrySound Now the import { InfiniteLoader, AutoSizer, List } from 'react-virtualized' I tried this but my bundle did not decrease in size. |
@alexparish That sucks. I will make this library treeshakable for v10. |
@TrySound That would be great. I believe the only impediment to tree-shaking the raw source code of this library is caused by the addition of the Having added
Out of interest, for v10 would you make the commonjs output tree-shakable? Is that even possible? |
@alexparish ignore node_modules {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
} |
And no, commonjs is not treeshakable. However rollup plugin commonjs may on some cases convert to treeshakable esm. |
@TrySound Ignoring node_modules only works for Webpack. I am having the same issue with Metro Bundler where I get the Any thoughts? |
@miguelocarvajal If there is such problem you probably overtranspile your vendors. Is it fast? |
@TrySound Fast as it has ever been :) To make sure its not my configuration I just tried creating a new project with react-native and I still get the same message. These are the steps I followed:
Just with those steps and now adding any other dependencies the app no longer runs due to that babel config. |
Hi @bvaughn ,
We are glad that this library is performing so well on mobile devices for us. One thing that we are concerned about is the bundle size. We are using webpack 2 for bundling with tree-shaking. Currently react-virtualized's size in our bundle can be seen below.
This is when we are using
InfiniteScroller
withList
. Even though I am fine with this, I would like to know whether this can be improved ? Because even slight reductions in file size can do wonders on mobile.The text was updated successfully, but these errors were encountered: