-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bundling js-ipfs and js-ipfs-api for the Browser #429
Comments
Moved to #398 (comment) |
Prob best to keep discussion here :)
|
Moving discussion back here. Re comments from @jbenet in the other issue
I am very happy to see simpler solutions that achieve the same level of gains, so far I have not seen one.
We are still node compatible, but would have a compilation step before hand, as we have for the browser or we have in go.
There is a lot of personal opinion in here, and I don't want to make this discussion about the design decisions made in ES2015 modules. Fact is that they allow deterministic static analysis by design, something which CommonJS, due to its dynamic nature not fully allows.
What people do is moving to ES2015 modules because at the current tooling state only Closure Compiler is able to remove the static part of unused CommonJS modules. All other tooling that I tested it not able to do this entirely.
We can, and we can't. Using Closure Compiler, with advanced optimizations (the only level that does give us these benefits) comes with a set of pretty hard draw backs.
I don't see this. Please read the details above again. We don't need to use webpack, but we also don't want to write the whole pipeline ourselves. Webpack has served as well in the past and continues to improve. For tree shaking there are multiple solutions and pipelines available, of which we could choose either with it's pros and cons. You can refer to the above mentioned The cost of transpiling ES2015 in 2016 to get a comparison of the different pipelines. |
I found another really good tool to analyse where the size is left. https://github.com/danvk/source-map-explorer will allow you to actually look into the minified version and with the help of source maps figure out where the code comes from. |
After more research I think I have to come to a better solution, that is less radical.
|
Also dropping Node 4 support, given that 6 is the new LTS version starting next month. |
Also I should mention, part of this effort will be ensuring |
@dignifiedquire I would like to recommend that you continue transpiring it. The most important browsers that would need it are mobile browsers. You could create 2 different versions though. Since before Devcon2 I've been busy working on other things, but I'm going to start reviewing this again to see if we can start using the ipfs-js libraries in our browser/RN code for uPort. The largest problem unless there have been many changes since I last looked at it, is the node first approach. I would really recommend using browser http abstractions as the core, such as Remember that for node it doesn't matter that you're pulling in a few extra dependencies. But for the browser it does. |
@pelle in what situations would you use our transpiled version over a bundle that you would generate yourself and transpile? |
@dignifiedquire The only function of a minimized dist file is for them to be included directly on a web page. Ideally you would CDN them somewhere. Large dependencies in production web apps will often be loaded separately to allow them to be cached by the browser and not reloaded if a minor app change happens. For the case of bundling them myself I don't need the dist files. I'll require the dependencies as they are and bundle my whole app. |
right but if you do seperate bundles in production you really need to generate them yourself. The current use case why we provide the dist files is for quick start and demos, both of which are usually not too concerned with strict broser compat. So I still think we should stop providing transpilled builds and only provide imple receipes to get a transpilliatiom pipeline setup for those that need one. |
If thats the only use case then thats fine though. I'm much more concerned with lowering the size of dependences on. |
First set of changes is up here: ipfs/aegir#65 I will use this as a baseline to make sure that modules are being built and working with a minimal config of just using babel + json loader in webpack. Which translates to babelify + browserify with no default config. |
Relevant ipfs-inactive/js-ipfs-http-client#416 as it right now looks kind of scary on install |
This was shipped in #485 :) so closing |
@dignifiedquire the cherry on top of this cake would be to have two quick start tutorials of how to bundle js-ipfs and js-ipfs-api with browsersify and webpack. |
) fix a couple of grammatical errors arrange function index in alphabetical order add more options to ipfs.add doc rename cid-version to cidVersion in the docs closes: ipfs#429 License: MIT Signed-off-by: Prabhakar-Poudel <yuvrajzohan@gmail.com>
JS IPFS is a large collection of modules that aim to implement IPFS in Node.js and the browser. As such the distributions of these modules has a specific set of constraints.
Our current setup is not bad, and does generate bundles usable in Node.js and the browser, but there are some pain points that need work.
Current Pain Points
readable-stream
is included 12 times in the currentjs-ipfs
browser bundle.be able to use browserify or webpack.
until we get a bug report.
Optimization Goals
Module Formats
There are two different module formats for JavaScript modules in main use today.
var dep = require('dependency')
import dep from 'dependency'
The current code base uses CommonJS.
Available Tooling
The tooling landscape is quite large today, with things developing and changing quite rapidly. The for us currently relevant tooling is listed below.
Module Bundlers
A module bundler can take in many JavaScript files and generate a bundle, which is usable in the browser.
ES2015 Transpilers
Transpilers can transform code written with ES2015 features and output code that is usable in ES5 (and lower) environments.
A good comparision of the differences in size and runtime can be found in The cost of transpiling ES2015 in 2016.
Proposal
Given the set of constraints mentioned above, the following is a list of steps I suggest to improve and solve our current pain points.
1. Improve build artifacts
Similar to what PouchDB does, the end result for Node.js and the browser should be a single file.
If there are differences between Node.js and browser, modules use two different entry points
src/index.js
- Original source for node.jssrc/index-browser.js
- Original source the browserFor the builds we target the same places as currently
dist/index.js
ES5 code for the browserlib/index.js
- ES5 code for node.jsbut
lib/index.js
will be a single file, fully transformed rather than still many files such that treeshaking and processing of things like webpack loaders already happend and this is runnable through in node.js directly.To make tooling aware of what is avaliable, the following should fields should be in
package.json
Benefits
Drawbacks
lib/index.js
is a bit harder to read as itis now a single large file.
2. Test webpack & browserify in CI
Benefits
Drawbacks
3. Move to ES2015 Modules
Benefits
Drawbacks
babel-register
.4. Carefully audit the dependency tree
Benefits
Drawbacks
Resources
Blog Posts
Issues on IPFS
The text was updated successfully, but these errors were encountered: