Skip to content

Commit 2030c14

Browse files
committed
Simplified building: using custom rollup config for web-worker creation
1 parent b4d617e commit 2030c14

File tree

5 files changed

+90
-118
lines changed

5 files changed

+90
-118
lines changed

.eslintrc.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module.exports = {
1313
ecmaVersion: 'latest',
1414
sourceType: 'module',
1515
},
16+
globals: {
17+
FinalizationRegistry: true,
18+
},
1619
rules: {
1720
'no-underscore-dangle': 0,
1821
'class-methods-use-this': 0,

package-lock.json

Lines changed: 49 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"pako": "^2.0.4",
8888
"parse-headers": "^2.0.2",
8989
"quick-lru": "^6.1.1",
90-
"web-worker": "^1.2.0",
90+
"web-worker": "^1.5.0",
9191
"xml-utils": "^1.0.2",
9292
"zstddec": "^0.1.0"
9393
},
@@ -100,6 +100,7 @@
100100
"@rollup/plugin-commonjs": "^21.0.1",
101101
"@rollup/plugin-node-resolve": "^13.1.3",
102102
"chai": "^4.2.0",
103+
"chai-as-promised": "^8.0.1",
103104
"chokidar-cli": "^3.0.0",
104105
"detect-node": "^2.0.4",
105106
"eslint": "^7.32.0",
@@ -125,15 +126,15 @@
125126
"typescript": "^4.5.5"
126127
},
127128
"scripts": {
128-
"prebuild": "npm run build:clean && npm run build:module",
129-
"build": "run-p build:browser build:node build:types",
130-
"build:clean": "rimraf dist-node/ dist-browser/ dist-module/",
131-
"build:node": "tsc --project tsconfig.build.json && shx echo \"{\\\"type\\\":\\\"commonjs\\\"}\" > dist-node/package.json",
129+
"prebuild": "npm run build:clean",
130+
"build": "npm run build:module && run-p build:browser build:node build:types",
131+
"build:clean": "shx rm -rf dist-node/ dist-browser/ dist-module/",
132+
"build:module": "shx mkdir -p dist-module && shx cp -rf src/* dist-module/ && rollup -c rollup.worker.config.js",
132133
"build:browser": "rollup -c rollup.config.js",
133-
"build:module": "shx mkdir -p dist-module && shx cp -rf src/* dist-module/ && node scripts/serialize-workers.cjs",
134+
"build:node": "tsc --project tsconfig.build.json && shx echo \"{\\\"type\\\":\\\"commonjs\\\"}\" > dist-node/package.json",
134135
"build:types": "tsc --outdir dist-module/",
135-
"watch:browser": "chokidar \"dist-module/*.js\" -c \"npm run build:browser\"",
136136
"watch:module": "chokidar \"src/*.js\" -c \"npm run build:module\"",
137+
"watch:browser": "chokidar \"dist-module/*.js\" -c \"npm run build:browser\"",
137138
"predev": "npm run build",
138139
"dev": "run-p watch:module watch:browser dev:serve",
139140
"dev:serve": "serve --listen 8090",

rollup.worker.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
3+
import baseConfig from './rollup.config.js';
4+
5+
export default {
6+
...baseConfig,
7+
input: 'dist-module/worker/decoder.js',
8+
output: {
9+
file: 'dist-module/worker/create.js',
10+
format: 'module',
11+
inlineDynamicImports: true,
12+
},
13+
plugins: [
14+
...baseConfig.plugins,
15+
{
16+
name: 'serialize worker and export create function',
17+
renderChunk(code) {
18+
return `\
19+
import Worker from 'web-worker';
20+
21+
export default function create() {
22+
const source = ${JSON.stringify(code)};
23+
return new Worker(typeof Buffer !== 'undefined'
24+
? 'data:application/javascript;base64,' + Buffer.from(source, 'binary').toString('base64')
25+
: URL.createObjectURL(new Blob([source], { type: 'application/javascript' })));
26+
}`;
27+
},
28+
},
29+
],
30+
};

scripts/serialize-workers.cjs

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)