Skip to content

Update build/bundle #206

@JayPanoz

Description

@JayPanoz

As seen in #205 and its comments we are aware we need to rethink build and distribution.

For context, we have been historically relying on Vite to deal with Readium CSS as ?inline – it is now ?raw thanks to the Injection API. And we’ve been using the recommended way of building,libraryMode.

This is an issue for tree-shaking though, as experienced by others but also us in Thorium Web, with the build size not optimised as it should be. This is not unexpected and is actually a known issue.

Insights from @smoores-dev:

Note for discussion: if we want to continue using vite/esbuild for transpilation, but stop bundling, we probably actually want to use .js extensions in our imports, not .ts, because esbuild doesn't support rewriteRelativeImportSpecifiers. If we instead switch to swc, then we can keep the .ts specifiers. Let me know what you're thinking on that front!

Also, on the note of unbundling — I think, in addition to (actually, contributing to) bundle size, there's an issue where the same package can end up included in the bundle multiple times, because each package is bundled separately, first, and dependencies are currently included in the bundle. This can mean that there are multiple instances of the same class definition, which don't get merged, which breaks some things (like instanceof checks).

And from Discord:

Re: unbundling and the raw imports — there is an esbuild raw plugin that handles the same import format that you currently use with vite. You could use this with plain esbuild or tsup to transpile without bundling!

I will give this a deeper look from PR’ing RTL + CJK, as it actually changes how Readium CSS is handled, so it will be a good starting point to handle this. In the meantime, any other feedback and input is greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions