Add mermaid.tiny.min.js. 69.7% size reduction.#4734
Conversation
Excludes elk and mindmap at build time
* sidv/splitChunks: chore: Add analyzer comment chore: Split chunks into folders chore: Split chunks into folders chore: Add defaultOptions to server chore: Split chunks into folders
* sidv/splitChunks: chore: Fix outfile names
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4734 +/- ##
==========================================
- Coverage 3.87% 3.87% -0.01%
==========================================
Files 412 413 +1
Lines 43134 43201 +67
Branches 664 666 +2
==========================================
+ Hits 1672 1673 +1
- Misses 41462 41528 +66
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
* sidv/splitChunks: Fix import
mermaid.tiny.min.js mermaid.tiny.min.js. 69.7% size reduction.
aloisklink
left a comment
There was a problem hiding this comment.
Nice! That's a massive size reduction!
I'm really against putting this in the mermaid package, because it will make the package bigger for everybody, even if they don't use the mermaid.tiny.min.js file, and it will add another file that we will never be able to get rid of without breaking backwards compatibility with CDNs.
I think this must go in a new package, maybe something like @mermaid-js/mermaid-tiny?
Two other recommendations that would be nice to fix, but not required:
-
Instead of changing
src/diagrams/.../detector.ts, can't we just prevent addingmindmapandflowchart/elkin the thediagram-orchestration.tsfile, e.g. modifying these lines of code:mermaid/packages/mermaid/src/diagram-api/diagram-orchestration.ts
Lines 74 to 77 in 5f95a26
If ESBuild is smart enough, it should do tree shaking automatically, and it will have the same effect.
-
I think the error diagram needs a more human readable message in case somebody does try to use
mindmaporflowchart-elkwithmermaid-tiny. We have to assume that users might not even know they're usingmermaid-tiny, e.g. if they're using a third-party Mermaid plugin.
The current unpacked size is 21MB, adding an extra 1MB to it is worth the tradeoff for not having to maintain and release another package. Moreover, this will only affect people using package managers, not actual end users.
Now it's just a file, if we use a package, we'll have to maintain that in sync with mermaid, which is a bigger headache than having a file in the package with 0 active maintenance requirement. |
I tried that first, the file size didn't change. But I was using a different approach then (not define). Let me try now. -- It worked! ❤️ |
Co-authored-by: Alois Klink <alois@aloisklink.com>
That would be out of scope for this PR. I did try a POC, but the changes will be extensive. Especially since we're not even registering the diagrams since 55266c4 |
I still don't agree with adding the Would uploading this as a GitHub Release asset be a better idea (e.g. using something like https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28)? This should be pretty easy to do (we just need to add another job in https://github.com/mermaid-js/mermaid/blob/develop/.github/workflows/release-publish.yml). Since GitHub Releases don't have an Regardless of what we pick, since adding another entry-point to mermaid is a pretty major change, we should get @knsv's approval first (maybe also other mermaid maintainers?). I think long-term, having it in a separate NPM package like
That's fair! It would be a nice feature to have, especially if custom Mermaid plugins become more popular (although since it's not a breaking change, that would be a feature that can go directly into the |
This could be a stop-gap measure till we have automated builds and separate packages. Also, I don't think the |
|
I have this idea for fully customizable mermaid that people can download, containing code for only the diagrams that they need, in a single bundle, without lazy loading. A browser based version could be done using esbuild-wasm, once the bundling in browser part is figured out. |
* next: chore: Move SVG import to comment. build docs Remove whitespace on empty line chore: Fix minify Documentation for #2509 Update all minor dependencies Update all patch dependencies make more `RectData` required and remove optional assignment use lineBreakRegex in `svgDrawCommon` fix svgDrawCommon import by adding `.js` add types to `svgDrawCommon.ts` convert `svgDrawCommon` to TS
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
into sidv/tinyMermaid * 'sidv/tinyMermaid' of https://github.com/mermaid-js/mermaid: [autofix.ci] apply automated fixes
|
I've published @mermaid-js/tiny, so now users can use <script src="https://cdn.jsdelivr.net/npm/@mermaid-js/tiny@11/dist/mermaid.tiny.js"></script> |
into sidv/tinyMermaid * 'sidv/tinyMermaid' of https://github.com/mermaid-js/mermaid: [autofix.ci] apply automated fixes

📑 Summary
Adds a tiny version of mermaid that is optimized for the web. It is a subset of the mermaid library and is designed to be used in the browser via CDN.
Usage via NPM
This package is not meant to be installed directly from npm. It is designed to be used via CDN.
If you need to use mermaid in your project, please install the full
mermaidpackage instead.Removals from mermaid
This does not support
Usage via CDN
Latest version
Specific version
Resolves #4616
📏 Design Decisions
Uses the define feature of esbuild to exclude mindmap and flowchart-elk during build time.
📋 Tasks
Make sure you