RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
292 stars 45 forks source link

Update build instructions for Webpack + add example config #97

Closed HDegroote closed 2 years ago

HDegroote commented 2 years ago

This config works on a small project of mine, but I do need to add new packages to the list of fallbacks every once in a while. If used for a bigger project, you will likely have to add more fallbacks, as described. But I think this should cover the dependencies of hyper-sdk itself. Perhaps you can try out this config on another browser-based project of yours?

Note: webpack throws a big warning for the sodium-javascript package, which does an odd hack. I remember reading about it in some github issue, but can't pinpoint the conversation right now. The gist of it was that it is supposed to break in the browser, so I guess that's okay. But I haven't added it to the readme because I don't fully understand it and don't want to provide incorrect information.

WARNING in ./node_modules/sodium-javascript/randombytes.js 23:6-13
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/sodium-javascript/index.js 27:8-32
 @ ./node_modules/sodium-universal/index.js 1:0-41
 @ ./node_modules/hypercore-crypto/index.js 1:15-42
 @ ./node_modules/dat-sdk/index.js 9:15-42
 @ ./Hyperdrive/01_Create_a_named_drive.js 11:12-30

The hack in question is:

  if (require != null) {
    // Node.js. Bust Browserify
    crypto = require('cry' + 'pto')
    if (crypto && crypto.randomBytes) return nodeBytes
  }

Resolves #96