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

Add es module build for browser installation #70

Merged
merged 5 commits into from
Feb 2, 2021

Conversation

acmiyaguchi
Copy link
Contributor

Thanks for this great package! I've had fun using it so far, and it's one of the few packages in the ecosystem that fits my needs.

I'm using a browser bundler for my application, so the current set of builds are problematic. When I use npm install midi-player-js for my web app, it also includes the require("fs") statement in loadFile. I did a couple things to resolve this:

  • Conditionally added a section for loadFile that rollup eliminates as a dead branch when being built for the browser
  • Add a es module for browser distribution under builds/index.browser.js. I add this to the package.json under browser so my bundler grabs the correct distribution.

I also removed the build directory from check ins. I left the browser directory alone, in case the github raw link was being used to source the script.

This works as expected in a small test page I made.

@@ -278,7 +278,7 @@ <h4 class="name" id="bytesProcessed"><span class="type-signature"></span>bytesPr

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="player.js.html">player.js</a>, <a href="player.js.html#line443">line 443</a>
<a href="player.js.html">player.js</a>, <a href="player.js.html#line447">line 447</a>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a suggestion, it might be worth removing the docs directory from check in to avoid the noise in PRs (and maybe autodeployed from CI).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

"scripts": {
"pretest": "npm run build",
"test": "mocha",
"build": "mkdir -p build && rollup -c && npm run docs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the mkdir call, which causes issues on Windows. Rollup seems to work fine without it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

"watch": "watch 'npm run build' src",
"docs": "jsdoc src README.md -d ./docs -t ./node_modules/minami",
"prepare": "npm run build",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to generate the bundle before installation since the build directory is now being excluded from vcs. For example when installing via git:

    "midi-player-js": "git+https://github.com/acmiyaguchi/MidiPlayerJS.git#browser",

@grimmdude
Copy link
Owner

Wow thanks @acmiyaguchi! This all looks great, truly appreciate your contribution. I know that require('fs') has been a thorn in some people's sides for a while.

Agree that docs should be handled differently so they're not always mixed up with code changes.

@grimmdude grimmdude merged commit 453665f into grimmdude:master Feb 2, 2021
@acmiyaguchi acmiyaguchi deleted the browser branch February 2, 2021 05:37
@acmiyaguchi acmiyaguchi restored the browser branch February 4, 2021 05:37
@vinzentt
Copy link

I'm still having he issue with fs module not found because this PR was merged to master without a release. Do you know when the next release is planned?

@grimmdude
Copy link
Owner

Hey @vinzentt, thanks for the reminder. I just published 2.0.14 to npm which includes this change.

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.

3 participants