Browser build #6
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I'm looking to evaluate policies in the browser and had a hard time bundling pbac.js so it could run there. I made some minor changes to the project to make that work. Your unit tests made it really easy to catch all my mistakes (I hope!).
Instead of require'ing both
lodashandlodash/fp, I switched to only usinglodash/fp. When you include both lodash.js and lodash.fp.js in a browser, the FP build replaces the non-FP build. By only using one of those packages, it's much easier to manage.I also only require
lodash/fpinstead of all the separate sub-modules to make it easier to externalize. Even when requiring separate packages, the bundle webpack was creating was over 200K with all the lodash dependencies. I understand there are ways to configure webpack to do "tree shaking", but I don't know how to do that yet.I replaced the
ipcheckpackage withipaddr.js.ipcheckdepended on the Node.jsnetmodule which made it unusable in the browser.I added a variable (
process.env.BROWSER) to do conditional compilation so I could avoid referencing theBufferclass in the browser build. I don't plan on using any binary attributes, but the references toBufferadded over 40K to the bundle so I compiled them out. I tried usingUint8Arrayto fulfill whatBufferwas doing.I removed the usage of
util.format. The shim webpack bundled for that had a dependency onBuffer.After all my changes, the pbac.js build is only 8K.
I added some new scripts to package.json to build the bundle. It writes to the dist folder, but that's ignored by Git. I included it in the npm package, though, so the unpkg CDN can find the build and make it available to browsers.
I added a separate script to run the tests with
BROWSERset. The tests are still running in Node.js, but theBROWSERvariable makes them exercise my alternate paths. Mocha can run in browsers, too, but I didn't try to get that to work.I also added my webpack configuration file and a very simple example using it in the browser. You need to run the build before that will work and you need to install webpack and the other new dependencies before that:
I hope these changes are OK. Let me know if you want me to make any updates. Thanks.