Skip to content

Commit

Permalink
vite mod just in parts
Browse files Browse the repository at this point in the history
  • Loading branch information
unit-404 committed Oct 17, 2024
1 parent 1ead69f commit e2d1324
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 498 deletions.
36 changes: 35 additions & 1 deletion vite-mod/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# Vite Mod file
# Vite mod for `worker.ts`

## Parts

Main code in transform...

```js
if (compressRE.test(id)) {
const chunk = await bundleWorkerEntry(config, id)
const b64c = Buffer.from(
await new Promise<Uint8Array>((r) =>
gzip(strToU8(chunk.code), { level: 9 }, (_, d) => r(d)),
),
).toString('base64')
return {
code: `const b64c = "${b64c}"; export default b64c;`,
// Empty sourcemap to suppress Rollup warning
map: { mappings: '' },
}
}
```

Import library `fflate`:

```js
// sometimes needs dedicated library for compress
import { gzip, strToU8 } from 'fflate'
```

Reg-ex and other variables:

```js
// reg-ex for check query
const compressRE = /[?&]compress\b/
```
Loading

0 comments on commit e2d1324

Please sign in to comment.