Skip to content

@git-diff-view/lowlight eagerly imports all highlight.js languages, adding ~870 KB to the bundle #58

Description

@wozaxi

Thanks for this great library!

Problem

@git-diff-view/lowlight calls createLowlight(all) at module scope (https://github.com/MrWangJustToDo/git-diff-view/blob/main/packages/lowlight/src/index.ts):

import { createLowlight, all } from "lowlight";
const lowlight = createLowlight(all);

Because @git-diff-view/core re-exports everything via export * from '@git-diff-view/lowlight', any import from @git-diff-view/react (or /vue, /solid, etc.) causes all 130+ highlight.js language grammars to be bundled — even if the consumer only needs one or two languages or provides their own highlighter via registerHighlighter.

This adds ~870 KB (minified) to the vendor bundle, which cannot be tree-shaken.

Expected behavior

Consumers who provide their own DiffHighlighter via the registerHighlighter prop should not incur the cost of bundling all highlight.js languages.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions