diff --git a/README.md b/README.md index bd399ac..735afc9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,19 @@ npm run build Then open `index.html` in a browser of choice. You're now ready to use your `level` database, backed by IndexedDB! +In order to reduce bundle size, the webpack configuration at [`webpack.config.js`](./webpack.config.js) excludes the [`buffer`](https://github.com/feross/buffer) polyfill. To store binary data, either change the webpack configuration, or use Uint8Array instead of Buffer. For example: + +```js +import { Level } from 'level' + +const db = new Level('webpack-starter', { + keyEncoding: 'view' +}) + +await db.put(new Uint8Array([1, 2]), 'example') +const example = await db.get(new Uint8Array([1, 2])) +``` + ## Contributing [`Level/webpack-starter`](https://github.com/Level/webpack-starter) is an **OPEN Open Source Project**. This means that: diff --git a/package.json b/package.json index e790380..ddb5a04 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ "test": "npm run build" }, "devDependencies": { - "assert": "^2.0.0", - "level": "^7.0.0", - "process": "^0.11.10", + "level": "^8.0.0", "webpack": "^5.2.0", "webpack-cli": "^4.1.0" }, diff --git a/src/main.js b/src/main.js index 072fc32..fceabfc 100644 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,7 @@ -import level from 'level' +import { Level } from 'level' async function main () { - const db = level('webpack-starter') + const db = new Level('webpack-starter') const output = document.getElementById('output') await db.put('beep', 'boop') diff --git a/webpack.config.js b/webpack.config.js index cb21f8c..c2e9233 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,25 +1,16 @@ const path = require('path') -const webpack = require('webpack') module.exports = { entry: './src/main.js', output: { filename: 'main.js', - path: path.resolve(__dirname, 'dist'), + path: path.join(__dirname, 'dist'), }, - plugins: [ - // Webpack 5 no longer polyfills 'process' - new webpack.ProvidePlugin({ - process: 'process/browser', - }), - ], + mode: 'production', resolve: { - fallback: { - // BREAKING CHANGE: webpack < 5 used to include polyfills for - // node.js core modules by default. This is no longer the - // case. - 'util': false, - 'assert': false + alias: { + // Skip buffer dependency of abstract-level + buffer: false } } };