Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

How to use dist/index.min.js in node-cli #1859

Closed
cloudbitsum opened this issue Jan 31, 2019 · 9 comments
Closed

How to use dist/index.min.js in node-cli #1859

cloudbitsum opened this issue Jan 31, 2019 · 9 comments
Labels
kind/support A question or request for support

Comments

@cloudbitsum
Copy link

Hi,
I am new so please excuse any basic questions? I am student in std-12 and learning IPFS. It looks great.
I want to know if there is any way to use index.min.js in node-cli.
I know that I can simply import ipfs by require("ipfs"). But the require() create a big node_module which is an issue for school project. Also I dont have option to build a browser based app.
So I am looking to use index.min.js in node-cli server side. Or some way to similarly generate a minified fine.

Doing a require of index.min.js gives error that window is missing.

Please help.

@alanshaw
Copy link
Member

The builds in dist are meant for the browser and won't work in Node.js. There's currently no build for Node.js so the only way is to npm i ipfs and require it.

From a technical standpoint it would be tricky to create a build for Node.js as it stands because it depends on crypto and storage modules that have a native component - i.e. they need to either be compiled for your system or provide a pre-built binary. If we wanted to provide a pre-built Node.js version we'd need to provide multiple builds for different systems and architectures that combine the builds for these native modules.

Storage is pluggable so you could create a build that doesn't have any native modules by using the filesystem datastore instead of leveldb but you'd probably need to fork some of the crypto modules used by libp2p or use the browser build of libp2p-crypto (actually a standalone browser build doesn't look like it's being published to npm cc @jacobheun). If you're interested in creating such a build then I'd welcome a PR and would do my best to help with you any issues you encounter.

I am interested in the possibility of someday providing pre-built "binaries" because for a user that is not using IPFS programmatically (they are just using the daemon) it'll be much faster to download and install and as you observed, space saving.

cc @hugomrdias this is relevant to our conversation on pre-builds for iim.

@alanshaw alanshaw added kind/support A question or request for support status/in-progress In progress labels Jan 31, 2019
@jacobheun
Copy link
Contributor

(actually a standalone browser build doesn't look like it's being published to npm cc @jacobheun)

@alanshaw I'm seeing the dist folder on npm and the browser field has the correct files for webpack to do the conversions. Is there something else missing for this I'm not seeing?

@alanshaw
Copy link
Member

ahhh, my mistake!

@ghost ghost removed the status/in-progress In progress label Jan 31, 2019
@cloudbitsum
Copy link
Author

Thanks @alanshaw
I will create one PR

@humanely
Copy link

This is very interesting. I can try

@humanely
Copy link

humanely commented Feb 12, 2019

@alanshaw This shall need target:'node' in aegir/src/config/webpack.config.js Right?
Or can we add such a flag in .aegir.js ?

@alanshaw
Copy link
Member

Yes I think you can override webpack settings in Aegir config.

Also relavant: https://github.com/zeit/pkg (thanks @hugomrdias)

@hugomrdias
Copy link
Member

Our aegir build is not meant for node things. Please open an issue in the ipfs/aegir with your use case and i'll have a look.

In the mean time check either pkg @alanshaw mentioned or https://github.com/zeit/ncc and see if any of these fit your use case.

@humanely
Copy link

Oh, well, I see. @cloudbitsum https://github.com/zeit/ncc is your thing. It would give you one require'able index.js

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

5 participants