Skip to content

Commit

Permalink
build: add process env to disable inline worker import
Browse files Browse the repository at this point in the history
  • Loading branch information
YunFeng0817 committed Sep 13, 2024
1 parent 23ed59f commit 0dcdf34
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CanvasContext } from '@rrweb/types';
import initCanvas2DMutationObserver from './2d';
import initCanvasContextObserver from './canvas';
import initCanvasWebGLMutationObserver from './webgl';
import ImageBitmapDataURLWorker from '../../workers/image-bitmap-data-url-worker?worker';
import ImageBitmapDataURLWorker from '../../workers/image-bitmap-data-url-worker?worker&inline'
import type { ImageBitmapDataURLRequestWorker } from '../../workers/image-bitmap-data-url-worker';

export type RafStamps = { latestId: number; invokeId: number | null };
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"vite.config.defaults.ts",
"tsconfig.json"
],
"globalPassThroughEnv": ["PUPPETEER_HEADLESS"],
"globalPassThroughEnv": ["PUPPETEER_HEADLESS", "DISABLE_WORKER_INLINING"],
"tasks": {
"prepublish": {
"dependsOn": ["^prepublish", "//#references:update"],
Expand Down
19 changes: 18 additions & 1 deletion vite.config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import dts from 'vite-plugin-dts';
import { copyFileSync } from 'node:fs';
import { defineConfig, LibraryOptions, LibraryFormats, Plugin } from 'vite';
import glob from 'fast-glob';
import { build, Format } from 'esbuild';
import { resolve } from 'path';
import { umdWrapper } from 'esbuild-plugin-umd-wrapper';

// don't empty out dir if --watch flag is passed
const emptyOutDir = !process.argv.includes('--watch');
/**
* Chrome web store does not allow base64 inline workers.
* For chrome extension, we need to disable worker inlining to pass the review.
*/
const disableWorkerInlining = process.env.DISABLE_WORKER_INLINING === 'true';

function minifyAndUMDPlugin({
name,
Expand Down Expand Up @@ -157,6 +161,19 @@ export default function (
},
}),
minifyAndUMDPlugin({ name, outDir }),
{
name: 'remove-worker-inline',
enforce: 'pre',
transform(code, id) {
if (!disableWorkerInlining) return;
if (/\.(js|ts|jsx|tsx)$/.test(id)) {
return {
code: code.replace(/\?worker&inline/g, '?worker'),
map: null,
};
}
},
},
...plugins,
],
}));
Expand Down

0 comments on commit 0dcdf34

Please sign in to comment.