Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Migrate build to vite #1033

Open
wants to merge 153 commits into
base: master
Choose a base branch
from
Open

Chore: Migrate build to vite #1033

wants to merge 153 commits into from

Conversation

Juice10
Copy link
Contributor

@Juice10 Juice10 commented Oct 21, 2022

  • Move plugins to /packages/plugins/PLUGIN_NAME
  • Move testing of plugins to their own packages
  • Move packer to its own package
  • Get tests working again in all packages
  • Add umd bundling to rrweb: depends on feat(lib): multiple entries for umd/iife vitejs/vite#10609 (or use workaround by running multiple vite builds, one for each entry) Multiple entry points/output in library mode? vitejs/vite#1736 (comment)
  • Unify all tsconfig.json files by extending them from /tsconfig.base.json
    • Fix any typescript code that fails due to unification
  • Update all .md files to reflect new file names and plugin locations
  • port bundling of rrweb-player to vite
  • fix errors from https://publint.dev/rrweb@2.0.0-alpha.4
  • setup yarn dev to build with --watch
  • move apply virtual style rules to node tests to rrweb from rrdom
  • consider adding an @rrweb/all convenience package that bundles: record/replay/pack/unpack/plugins-console-record/plugins-console-replay
  • make sure repl and stream work
  • make sure benchmarks run
  • fix CI

Tests passing:

  • rrdom/
  • rrdom-nodejs/ failing: needs to be updated to jest 29 like rrdom
  • rrvideo/ failing: needs to be updated to jest 29 like rrdom
  • rrweb/ failing
  • rrweb-player/ no tests
  • rrweb-snapshot/ 2 failed tests "rrweb is not defined"
  • @rrweb/packer
  • @rrweb/types no tests
  • web-extension/ no tests
  • plugins/rrweb-plugin-canvas-webrtc-record/ no tests
  • plugins/rrweb-plugin-canvas-webrtc-replay/ no tests
  • plugins/rrweb-plugin-console-record/ failing locally some times; vite adds a console.debug message when included
  • plugins/rrweb-plugin-console-replay/ no tests
  • plugins/rrweb-plugin-sequential-id-record/ no tests
  • plugins/rrweb-plugin-sequential-id-replay/ no tests

Build passing:

  • rrdom/
  • rrdom-nodejs/
  • rrvideo/ (not with vite yet)
  • rrweb/
  • rrweb-player/ failing: rrweb does not export packer, packers should be moved to own package
  • rrweb-snapshot/
  • @rrweb/packer
  • @rrweb/types
  • web-extension/
  • plugins/rrweb-plugin-canvas-webrtc-record/
  • plugins/rrweb-plugin-canvas-webrtc-replay/
  • plugins/rrweb-plugin-console-record/
  • plugins/rrweb-plugin-console-replay/
  • plugins/rrweb-plugin-sequential-id-record/
  • plugins/rrweb-plugin-sequential-id-replay/

publint passing (yarn build && yarn test; npx publint; attw --pack .):

  • rrdom/
  • rrdom-nodejs/
  • rrvideo/ (not with vite yet)
  • rrweb/ still needs umd version to make it work
  • rrweb-player/ not using vite yet, all type imports are broken
  • rrweb-snapshot/
  • @rrweb/packer
  • @rrweb/types
  • @rrweb/all
  • web-extension/ (not an exposed package)
  • plugins/rrweb-plugin-canvas-webrtc-record/
  • plugins/rrweb-plugin-canvas-webrtc-replay/
  • plugins/rrweb-plugin-console-record/
  • plugins/rrweb-plugin-console-replay/
  • plugins/rrweb-plugin-sequential-id-record/
  • plugins/rrweb-plugin-sequential-id-replay/

@Yuyz0112
Copy link
Member

going to look into this!

BTW, have you ever considered tsup?

@Juice10
Copy link
Contributor Author

Juice10 commented Oct 22, 2022

@Yuyz0112

going to look into this!

BTW, have you ever considered tsup?

To be honest I hadn't before reading your comment. Vite has so much momentum behind it and such broad support (libraries, svelte, vue, react, css, assets etc.), way less config heavy than the incumbents. And I felt really happy with it after ripping out webpack and raw rollup from a number of projects and replacing them with Vite. That made me think it was a good fit for us.
I have taken some time to get familiar with tsup and try it out. And I really love the low config nature of tsup as well, I think it may even be doing an even better job at it than Vite.
tsup uses esbuild + (a little) rollup under the hood which is super similar to Vite, although according to Vite's documentation esbuild is lacking in some features (eg. CSS support) and that's why they use rollup more for the production builds.

But for some reason while using tsup on rrweb I end up bumping into errors while bundling. Bundling the normal files is fine but generating the typescript dts files it seems to have issues with.

One thing I really like about Vite is that it comes with vitest, a super fast, drop in replacement for jest. Because it uses Vite under the hood, that's one less configuration step that needs to happen, which will make it easier for us to create packages (for example one per plugin) without all the configuration overhead.
Jest seems to have massive issues with esm modules since it was built in a pre-esm world, and I think we'll start bumping into that more and more. Vitest would be an easy solution for that.

Turns out what we where doing by overwriting `public textContent: string | undefined` as a getter in a subclass is something that isn't allowed in typescript. Because we where using `// @ts-ignore`  to hide this error our bundler chose to allow the overwrite. Vite choses to disallow the overwrite making all subclasses' `textContent` undefined.
To mitigate this we're using an abstract class, which does allow sub classes to decide if they wan't to use getters or not.
This removes console from rrweb-all.js
@Yuyz0112
Copy link
Member

@Juice10 Thanks for the detailed explanation!

I mentioned tsup because in some other projects we found vite is good enough for packaging an app, but it still needs more config works to package a library. So we use vite to dev and build apps and tsup to build libraries.
So basically it's a supplement instead of a replacement.

If rrweb is happy with vite, then a tsup may not be needed.

Great work!

@Juice10
Copy link
Contributor Author

Juice10 commented Jan 16, 2023

We need to make sure this PR also addresses the following issues: https://publint.dev/rrweb@2.0.0-alpha.4

@YunFeng0817 YunFeng0817 linked an issue Feb 6, 2023 that may be closed by this pull request
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Publish ESM on CDN
3 participants