Skip to content

Commit

Permalink
docs: add examples with Vite and Webpack5 (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonghaYao committed Oct 25, 2023
1 parent ea5368c commit 37ea11e
Show file tree
Hide file tree
Showing 23 changed files with 8,365 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/vite/.gitignore
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
37 changes: 37 additions & 0 deletions examples/vite/README.md
@@ -0,0 +1,37 @@
# Vite Workerpool Example

```bash
$ npm install
$ npm run dev
$ npm run build
```

## Notice
workerpool runs well in Vite and requires some adaptation in terms of Web Workers when used.

```js
import WorkerURL from './worker/worker?url&worker'
const pool = workerpool.pool(WorkerURL, {
maxWorkers: 3,
workerOpts: {
// By default, Vite uses a module worker in dev mode, which can cause your application to fail. Therefore, we need to use a module worker in dev mode and a classic worker in prod mode.
type: import.meta.env.PROD ? undefined : "module"
}
});
```

```js
// worker.js
import workerpool from 'workerpool'
// a deliberately inefficient implementation of the fibonacci sequence
function fibonacci(n) {
if (n < 2) return n;
return fibonacci(n - 2) + fibonacci(n - 1);
}

// create a worker and register public functions
workerpool.worker({
fibonacci: fibonacci
});

```
13 changes: 13 additions & 0 deletions examples/vite/index.html
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Solid + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>

0 comments on commit 37ea11e

Please sign in to comment.