Skip to content

Commit

Permalink
Bump level from 7 to 8 and remove polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Jul 1, 2022
1 parent 605c337 commit c6db89d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
19 changes: 5 additions & 14 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -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
}
}
};

0 comments on commit c6db89d

Please sign in to comment.