Skip to content

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

@wozaxi

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.

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