oampo / Audiolet

A JavaScript library for real-time audio synthesis and composition from within the browser
http://oampo.github.com/Audiolet/
Apache License 2.0
894 stars 117 forks source link

commonjs support #59

Open konsumer opened 9 years ago

konsumer commented 9 years ago

I would like CommonJS support for using in browserify (and others,) which might help simplify the build process & better track dependencies, too.

Here is an example package.json file:

{
  "name": "audiolet",
  "version": "1.0.0",
  "description": "Real-time audio synthesis and composition from within the browser",
  "main": "src/audiolet/commonjs.js",
  "repository": {
    "type": "git",
    "url": "http://github.com/oampo/Audiolet.git"
  },
  "bugs": {
    "url": "http://github.com/oampo/Audiolet/issues"
  },
  "scripts": {
    "build": "browserify src/audiolet/commonjs.js --standalone Audiolet -o src/audiolet/Audiolet.js && uglifyjs src/audiolet/Audiolet.js -o src/audiolet/Audiolet.min.js"
  },
  "devDependencies": {
    "browserify": "^8.0.3",
    "uglify-js": "^2.4.16"
  },
  "dependencies": {
    "sink.js": "^0.0.1"
  }
}

In this example src/audiolet/commonjs.js should be an entry point that exposes the API with module.exports, and you can build standalone versions (for plain browser-globals & requirejs) with npm run build.

If you don't want to go full-on into browserify, etc, support for CommonJS would still enable others who use it to use audiolet easier (and without adding script tags to html.)

if this is published to npm, users can do npm install audiolet to install in their project & use it like this:

var Audiolet = require('audiolet');

Since browserify will build versions for others (requirejs, browser-global) you don't have to manage concatenating the files & if the user uses a module system that avoids browser-globals, they won't be exposed.

Also, as a sidenote, this will add server-side node to your available deployment targets. sink,js already targets node server-side sound, so it should work pretty well, natively.

The real work is going through all the files and setting up the CommonJs dependencies in every file. I am happy to do this work, if all this sounds like a good idea.

oampo commented 9 years ago

Hey David,

I've really not had much time to put into Audiolet for quite a while now, and it would be really nice to see it become a bit more modern looking. CommonJS and Node support would be pretty high on the list of priorities, so yeah, if you are up for doing the work I'll be happy to merge it. Hopefully it'll kick-start me to clean up some more rough edges and start doing a bit of work on this again!

Cheers, Joe

konsumer commented 9 years ago

I am working on a project that I hope to use it in, so I am happy to lend a hand.