Skip to content

Commit

Permalink
ADD infos to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Feb 9, 2024
1 parent 848873d commit 7a7fd5d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs-src/docs/rx-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ slug: rx-server.html

# RxDB Server

The RxDB Server Plugin makes it possible to spawn a server on top of a RxDB database that offers multiple types of endpoints for various usages. It can spawn basic CRUD REST endpoints or even realtime replication endpoints that can be used by the client devices to replicate data. The RxServer plugin is designed to be used in Node.js but you can also use it in Deno, Bun or the Electron "main" process.
The RxDB Server Plugin makes it possible to spawn a server on top of a RxDB database that offers multiple types of endpoints for various usages. It can spawn basic CRUD REST endpoints or even realtime replication endpoints that can be used by the client devices to replicate data. The RxServer plugin is designed to be used in Node.js but you can also use it in Deno, Bun or the Electron "main" process. You can use it either as a **standalone server** or add it on top of an **exisiting http server** (like express) in nodejs.

Check failure on line 8 in docs-src/docs/rx-server.md

View workflow job for this annotation

GitHub Actions / test-code-style

exisiting ==> existing

**NOTICE:** The server plugin is in beta mode and the API might be changed without a major RxDB release.

Expand Down
4 changes: 4 additions & 0 deletions docs-src/docs/rx-storage-shared-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const database = await createRxDatabase({
});
```

## Building a custom worker

To build a custom `worker.js` file, check out the webpack config at the [worker](./rx-storage-worker.md#building-a-custom-worker) documentation. Any worker file form the worker storage can also be used in a shared worker because `exposeWorkerRxStorage` detects where it runs and exposes the correct messaging endpoints.

## Passing in a SharedWorker instance

Instead of setting an url as `workerInput`, you can also specify a function that returns a new `SharedWorker` instance when called. This is mostly used when you have a custom worker file and dynamically import it.
Expand Down
57 changes: 57 additions & 0 deletions docs-src/docs/rx-storage-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,63 @@ const database = await createRxDatabase({
});
```

## Building a custom worker

The easiest way to bundle a custom `worker.js` file is by using webpack. Here is the webpack-config that is also used for the prebuild workers:

```ts
// webpack.config.js
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const projectRootPath = path.resolve(
__dirname,
'../../' // path from webpack-config to the root folder of the repo
);
const babelConfig = require(path.join(projectRootPath, 'babel.config'));
const baseDir = './dist/workers/'; // output path
module.exports = {
target: 'webworker',
entry: {
'my-custom-worker': baseDir + 'my-custom-worker.js',
},
output: {
filename: '[name].js',
clean: true,
path: path.resolve(
projectRootPath,
'dist/workers'
),
},
mode: 'production',
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: babelConfig
}
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.mjs', '.mts']
},
optimization: {
moduleIds: 'deterministic',
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
})],
}
};
```

## One worker per database

Expand Down

0 comments on commit 7a7fd5d

Please sign in to comment.