Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add examples with Vite and Webpack5 (#408)
- Loading branch information
Showing
23 changed files
with
8,365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.