-
Notifications
You must be signed in to change notification settings - Fork 522
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
Provide efficient webpack helpers for tree-shaking + DCE #548
Provide efficient webpack helpers for tree-shaking + DCE #548
Comments
I'd like to drop in my two cents, as I'm currently trying to set up our app that uses Victory to use Webpack 2 with tree shaking... and I'm having big problems with it. At the moment I'm having lots of errors like this when I'm trying to run a production build: ERROR in ./~/d3-interpolate/src/basis.js
Module parse failed: /my_app/node_modules/babel-loader/lib/index.js??ref--0-0!/my_app/node_modules/d3-interpolate/src/basis.js Cannot read property 'name' of null
You may need an appropriate loader to handle this file type.
TypeError: Cannot read property 'name' of null
at Parser.walkFunctionDeclaration (/my_app/node_modules/webpack/lib/Parser.js:539:39)
at Parser.walkStatement (/my_app/node_modules/webpack/lib/Parser.js:436:32)
at Parser.walkExportDefaultDeclaration (/my_app/node_modules/webpack/lib/Parser.js:613:9)
at Parser.walkStatement (/my_app/node_modules/webpack/lib/Parser.js:436:32)
at Parser.walkStatements (/my_app/node_modules/webpack/lib/Parser.js:419:9)
at Parser.parse (/my_app/node_modules/webpack/lib/Parser.js:1193:8)
at doBuild.e (/my_app/node_modules/webpack/lib/NormalModule.js:288:17)
at runLoaders (/my_app/node_modules/webpack/lib/NormalModule.js:206:11)
at /my_app/node_modules/loader-runner/lib/LoaderRunner.js:370:3
at iterateNormalLoaders (/my_app/node_modules/loader-runner/lib/LoaderRunner.js:211:10)
at iterateNormalLoaders (/my_app/node_modules/loader-runner/lib/LoaderRunner.js:218:10)
at /my_app/node_modules/loader-runner/lib/LoaderRunner.js:233:3
at context.callback (/my_app/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at /my_app/node_modules/babel-loader/lib/index.js:159:14
at /my_app/node_modules/babel-loader/lib/fs-cache.js:76:24
at /my_app/node_modules/babel-loader/lib/fs-cache.js:31:14
at Gunzip.onEnd (zlib.js:227:5)
at emitNone (events.js:91:20)
at Gunzip.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
@ ./~/d3-interpolate/index.js 3:0-58
@ ./~/victory-core/lib/victory-animation/util.js
@ ./~/victory-core/lib/victory-animation/victory-animation.js
@ ./~/victory-core/lib/index.js
@ ./~/victory/src/index.js
@ ./src/charts/styles/MyChart.js Previously I thought I have a problem with D3 but it seems the ES2015 (Harmony) module support of D3 is already implemented. However, this thread makes me think that the reason might be Victory. I've understood that to make tree shaking work in Webpack 2, one needs to set
This configures Webpack to primarily use ES2015 modules provided by 3rd party packages instead of other builds. So... to answer the question of this issue, I think Victory should also provide ps. I'm willing to help (at least by testing) because this issue is quite urgent for us. |
@TomiS -- A near-term hack for this that should work is available at: https://github.com/FormidableLabs/victory-line-experiments/blob/master/webpack.config.js (You'll need to (1) implement a And I think we can turn this around the general solution fairly quickly if we get a little bandwidth... |
Also, to properly set expectations with webpack2 tree shaking, there are still underlying issues with webpack itself to getting to a completely DCE'd final bundle, discussed here: #549 (But we should at least get rid of the "everything problem" with using the es5 |
@ryan-roemer Cool, thanks. I managed to get it working. In addition to what you said, for my build I also had to 1) include all D3 modules to babel-loader, 2) add babel include and alias also for And after all this, it seems the bundle is larger than with regular build :D It didn't surprise though, as I've read about similar experiences in other threads. |
Yeah, while initially such a super hyped-up thing, tree-shaking really is a fickle beast. I think in parallel to all of this finding a solution to #549 will likely have us end up with an internal refactor along the lines of @thomasthiebaud 's suggestions in #547 where we: admit tooling defeat and just do all the one-off, full-path imports for everything but the deliberate multiple re-export |
@ryan-roemer Not sure if this helps, but were you aware of this plugin: https://www.npmjs.com/package/babel-plugin-transform-imports |
@TomiS -- Not specifically, so thanks for the reference! I've been on private projects where someone wrote a more-tailored version of exactly this that relied on guaranteed conventions in file naming / export patterns. I was offhand even thinking we could do a bespoke version for Victory. I will definitely consider this as an easier alternative to full internal one-off refactor! |
@ryan-roemer Nice to hear it might be helpful. I just stumbled upon that today and installed it. At least it seems to work for |
add a voronoiBlacklist prop and ignore children with matching names
Moving discussion from #547 to the broader one: how to provide end users with the most terse bundle. I forget how much we talked about this before, but we could do a
package.json:browser
orpackage.json:SOME_OTHER_MAIN
that webpack picks up that points tosrc
, but then run into the problem of everyone needing fully compatible babel builds.1. Alias Option
One option is providing the resolves
src
paths as in the experiment repo'swebpack
config as a top-level provided thing so in your webpack config you could do something like:2. Different Main Option
A perhaps lighterweight custom idea is provide a custom
victory
specific namespace for: https://webpack.github.io/docs/configuration.html#resolve-packagemains that isn't in the defaults for webpack1:["webpack", "browser", "web", "browserify", ["jam", "main"], "main"]
The reason why we need to avoid the defaults is otherwise everyone would need the victory-specific babel set up to be able to use victory, which isn't what we want.
So, like
package.json:browser-victory
that folks then explicitly add to webpack1resolve.packageMains
to then need + use babel building like in the experiment repo at: https://github.com/FormidableLabs/victory-line-experimentsAlso, we need a webpack2-amenable configuration that also works with the decided scheme: https://webpack.js.org/configuration/resolve/#resolve-mainfields
Current strawman:
es
directory (out of source, but published) likeredux
does.For a good reference, see: https://github.com/reactjs/redux/blob/master/package.json
Other Notes:
/cc @boygirl @chrisbolin @thomasthiebaud
The text was updated successfully, but these errors were encountered: