Files
rrweb/packages/web-extension/vite.config.ts
Yun Feng b837600e80 rrweb extension implementation (#1044)
* feat: add rrweb web-extension package

* refactor: make the extension suitable for manifest v3

* update tsconfig.json

* use version_name rather than recorder_version in manifest.json

* update manifest.json

* enable to keep recording after changing tabs

* enable to record between tabs and urls

* fix CI error

* try to fix CI error

* feat: add pause and resume buttons

* feat: add a link to new session after recording

* improve session list

* refactor: migrate session storage from chrome local storage to indexedDB

* feat: add pagination to session list

* fix: multiple recorders are started after pausing and resuming process

* fix: can't stop recording on firefox browser

* update type import of 'eventWithTime'

* fix CI error

* doc: add readme

* Apply suggestions from Justin's code review

Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com>

* refactor: make use of webNavigation API to implement recording consistent during page navigation

* fix firefox compatibility issue and add title to pages

* add mouseleave listener to enhance the recording liability

* fix firefox compatibility issue and improve the experience of recording resume after closing tabs

* update tsconfig

* upgrade vite-plugin-web-extension config to fix some bugs on facebook web page

* update import links

* refactor: cross tab recording mechanism

apply Justin's suggestion

* refactor: slipt util/index.ts into multiple files

* implement cross-origin iframe recording

* fix: regression of issue: ShadowHost can't be a string (issue 941)

* refactor shadow dom recording to make tests cover key code

* Apply formatting changes

* increase the node memory limitation to avoid CI failure

* Create lovely-pears-cross.md

* Apply formatting changes

* Update packages/web-extension/package.json

* Update .changeset/lovely-pears-cross.md

* update change logs

* delete duplicated property

---------

Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com>
2026-04-01 12:00:00 +08:00

107 lines
3.1 KiB
TypeScript

import {
defineConfig,
LibraryFormats,
LibraryOptions,
PluginOption,
} from 'vite';
import webExtension, { readJsonFile } from 'vite-plugin-web-extension';
import zip from 'vite-plugin-zip';
import * as path from 'path';
import type { PackageJson } from 'type-fest';
import react from '@vitejs/plugin-react';
function useSpecialFormat(
entriesToUse: string[],
format: LibraryFormats,
): PluginOption {
return {
name: 'use-special-format',
config(config) {
const shouldUse = entriesToUse.includes(
(config.build?.lib as LibraryOptions)?.entry,
);
if (shouldUse) {
config.build ??= {};
// @ts-expect-error: lib needs to be an object, forcing it.
config.build.lib ||= {};
// @ts-expect-error: lib is an object
config.build.lib.formats = [format];
}
},
};
}
export default defineConfig({
root: 'src',
// Configure our outputs - nothing special, this is normal vite config
build: {
outDir: path.resolve(
__dirname,
'dist',
process.env.TARGET_BROWSER as string,
),
emptyOutDir: true,
},
// Add the webExtension plugin
plugins: [
react(),
webExtension({
// A function to generate manifest file dynamically.
manifest: () => {
const packageJson = readJsonFile('package.json') as PackageJson;
const isProduction = process.env.NODE_ENV === 'production';
type ManifestBase = {
common: Record<string, unknown>;
chrome: Record<string, unknown>;
firefox: Record<string, unknown>;
};
const originalManifest = readJsonFile('./src/manifest.json') as {
common: Record<string, unknown>;
v2: ManifestBase;
v3: ManifestBase;
};
const ManifestVersion =
process.env.TARGET_BROWSER === 'chrome' && isProduction ? 'v3' : 'v2';
const BrowserName =
process.env.TARGET_BROWSER === 'chrome' ? 'chrome' : 'firefox';
const commonManifest = originalManifest.common;
const manifest = {
version: packageJson.version,
author: packageJson.author,
version_name: packageJson.dependencies?.rrweb?.replace('^', ''),
...commonManifest,
};
Object.assign(
manifest,
originalManifest[ManifestVersion].common,
originalManifest[ManifestVersion][BrowserName],
);
return manifest;
},
assets: 'assets',
browser: process.env.TARGET_BROWSER,
webExtConfig: {
startUrl: ['github.com/rrweb-io/rrweb'],
watchIgnored: ['*.md', '*.log'],
},
additionalInputs: ['pages/index.html', 'content/inject.ts'],
}),
// https://github.com/aklinker1/vite-plugin-web-extension/issues/50#issuecomment-1317922947
// transfer inject.ts to iife format to avoid error
useSpecialFormat(
[path.resolve(__dirname, 'src/content/inject.ts')],
'iife',
),
process.env.ZIP === 'true' &&
zip({
dir: 'dist',
outputName: process.env.TARGET_BROWSER,
}),
],
resolve: {
alias: {
'~': path.resolve(__dirname, './src'),
},
},
});