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

wip: example with rollup #7

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

wip: example with rollup #7

wants to merge 1 commit into from

Conversation

oliveriosousa
Copy link
Contributor

@oliveriosousa oliveriosousa commented Jul 27, 2021

This PR is a WIP example of bundling IPFS using RollupJS.

Since js-ipfs uses CommonJS and RollupJS is an ESModule bundler the setup requires some additional configuration.
To overcome this, it was imported the following necessary plugins:

  • @rollup/plugin-commonjs: Plugin to convert CommonJS modules to ES6, so they can be included in a Rollup bundle
  • @rollup/plugin-json: Plugin which Converts .json files to ES6 modules.
  • @rollup/plugin-node-resolve: Plugin which locates modules using the Node resolution algorithm, for using third party modules in node_modules.
  • snowpackjs/rollup-plugin-polyfill-node: A modern Node.js polyfill for your Rollup bundle.

See: rollup.config.js

But it is getting some errors when performing the bundle,

(!) Circular dependencies (!) Circular dependencies polyfill-node.global.js -> polyfill-node.global.js node_modules/ipfs-bitswap/src/types/message/index.js -> node_modules/ipfs-bitswap/src/types/message/entry.js -> node_modules/ipfs-bitswap/src/types/wantlist/index.js -> node_modules/ipfs-bitswap/src/types/message/index.js node_modules/ipfs-bitswap/src/types/message/index.js -> node_modules/ipfs-bitswap/src/types/message/entry.js -> node_modules/ipfs-bitswap/src/types/wantlist/index.js -> /Users/oliveriosousa/Projects/PL/js-ipfs-examples/examples/browser-rollup/node_modules/ipfs-bitswap/src/types/message/index.js?commonjs-proxy -> node_modules/ipfs-bitswap/src/types/message/index.js

Even with circular dependencies, rollup generates a js file but when used by the app it is possible to check some mistakes, such as:

const isElectron$1 = require('is-electron');

console in the browser:

index.js:289 Uncaught ReferenceError: require is not defined

Any suggestions?

TODO

  • Fix bundle configuration
  • Add tests
  • Improve example
  • Improve readme

cc @hugomrdias

@oliveriosousa oliveriosousa marked this pull request as draft August 2, 2021 15:24
@oliveriosousa oliveriosousa mentioned this pull request Aug 10, 2021
3 tasks
@achingbrain
Copy link
Contributor

Since js-ipfs uses CommonJS

js-ipfs is all ESM now, so you may be able to simplify this a bit. Most deps are still CJS though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants