From ee0c92a4c2e43062156180bc3e8dca39f8184776 Mon Sep 17 00:00:00 2001 From: Steve Hartken Date: Thu, 6 Feb 2020 13:33:07 -0500 Subject: [PATCH] Added docs about webpack config This commit provides a webpack config for a bundle similiar to browserify. Browserify bundles to an empty function for `fs`, and for each module declares `fs` as a `graceful-fs` require. https://benclinkinbeard.com/posts/how-browserify-works/ The webpack bundle built from this commit's config resolves `graceful-fs` as an alias to `fs`. `fs` used in dat-sdk/index for browser/hyperdrive IO: https://github.com/random-access-storage/random-access-web --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 73fcb00..ff98fa7 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,29 @@ trie.put('key', 'value', () => { ``` +## Examples (webpack.config.js) + +To bundle with webpack instead of browserify, resolve the `fs` module with the `graceful-fs` module. + +```js +const path = require('path') + +module.exports = { + entry: './src/dat.js', + target: 'web', + resolve: { + alias: { + fs: 'graceful-fs' + } + }, + output: { + filename: 'dat.js', + path: path.resolve(__dirname, 'dist') + } +} + +``` + ## API (Promise) ### `const {DatArchive, destroy} = SDK({ storageOpts, swarmOpts, driveOpts, coreOpts, dnsOpts })`