Skip to content
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

Entry point and bundling changes #368

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Entry point and bundling changes #368

wants to merge 5 commits into from

Conversation

elboletaire
Copy link
Member

@elboletaire elboletaire commented Mar 26, 2024

This PR leaves the bundle exactly identical as the one we're currently generating, but brings some improvements to the way we were bundling the SDK:

Bundling changes

The external packages are now all taken from package.json dependencies field. The only exception is @vocdoni/proto/vocdhain, since the import does not match with the field in package.json.

Other than that, right now deciding if a dependency should be bundled or not is just a matter of placing it in devDependencies or dependencies.

Also, sourcemap generation has been set to be only done if NODE_ENV == 'development', since the final npm package should not have sourcemaps. Rollup.js' documentation is not very clear about what node env is being used during --watch mode, so right now it may be causing the same effect as having it set to false.

Entry point changes

The entry point has been changed to src/index.ts. This is done this way because, while developing, having the typescript as an entry point allows us to link the SDK to other projects and directly make changes to the SDK without requiring us to build in-between. This, of course, requires the end-developer to be bundling with something that is typescript compatible.

Since we don't need to build in-between anymore, the prepare npm script has been removed too.

To properly have the entry points defined for the npm package, a prepack script calling clean-package has been added. This script will ensure to modify the package.json file and add the entries required to access the bundled packages (exactly as we had it).

Note: due to this prepack script, running yarn pack locally will result in a modified package.json that should not be committed, ever. A postpack script will ensure to leave your package.json file like it was before the pack process.

Things I think this PR may address

We had issues in the past dealing with packages like axios, and I think that was due to the confusing way we were defining external packages, and because we were (accidentally) trying to bundle it into our SDK. Axios should not be bundled into our final package, instead, it should be defined as a dependency. Doing it this way, and given the changes done to the bundling configuration, this package shouldn't give any problems whatsoever.

Note: peerDependencies were not considered into the bundling because we're not using them here (and I don't see a reason for it tbh).

Why draft?

Because everything I've said is right except for the UMD/IIFE package (we're only bundling a UMD package). The idea behind a UMD package is that it should work without other external dependencies, so I should properly check it's being built that way. We can also consider dumping this version for now, since it doesn't seem to be a real need from the community for it.

Copy link

github-actions bot commented Mar 26, 2024

size-limit report 📦

Path Size
dist/index.js 1.54 MB (-0.13% 🔽)
dist/index.mjs 1.54 MB (-0.14% 🔽)
dist/index.umd.js 1.54 MB (-0.15% 🔽)

@elboletaire
Copy link
Member Author

elboletaire commented Mar 26, 2024

I'll need to review how the import checks are done too, since I changed the entry points.

Edit: I simply forgot about updating the github actions and run a required yarn build (not required previously due to the prepare script now removed).

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

Successfully merging this pull request may close these issues.

None yet

1 participant