question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundling for browser usage

See original GitHub issue

Hi, not really an issue, just wondering if it’s actually possible to use Shiki in browser instead of node? I have tried to bundle it with webpack and https://github.com/Jam3/babel-plugin-static-fs plugin, but still getting errors related to fs module calls for Onigasm and etc.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
zikaaricommented, Jun 13, 2020

Author of onigasm here. There is absolutely no problem running it in browsers, in fact, it was designed to be run in browsers for one of my own projects (now defunct).

It works perfectly fine with webpack with minimal config changes, just define a rule in webpack config to use file-loader for any import asking for *.wasm file.

Input

// src/index.ts
await loadWASM(await import('onigasm/lib/onigasm.wasm'))`

Output

// out/bundle.eu21df1.js
loadWASM('build/onigasm.8ug81e3.wasm').then(...)`

Note: Webpack might try to use it’s on WASM loader, despite the explicit rule. If that happens, fix this like this - https://github.com/webpack/webpack/issues/7264#issuecomment-388377363 The entire thread is a great read

2reactions
octrefcommented, Feb 6, 2020

@canibanoglu Even if that’s doable, is it desirable at all? Loading several MB of WASM and then the grammars to do syntax highlighting on client side? I initially thought of shiki as an library, on either a static site generator system or locally, to faithfully reproduce VS Code’s highlighting. I still think that’s useful enough. If you need to dynamically do syntax highlighting in browser, maybe Monaco or Highlight.js would be better choices?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Smart Bundling: How To Serve Legacy Code Only To Legacy ...
A quick look at caniuse.com's usage table reveals that evergreen browsers occupy a lion's share of the browser market — more than 75%....
Read more >
Demystifying Code Bundling with JavaScript Modules
Of course, bundling often means an increase in file size. Since website loading time is a prime concern for users, it's important to...
Read more >
GitHub - laander/is-bundling-for-browser-or-node
Uses package.json fields "browser" and "main" to check whether code is bundled for browser or node - GitHub ...
Read more >
How does browser support impact JavaScript bundle size?
Dropping support for older browsers, or serving separate bundles to them, can help reduce JavaScript bundle size.
Read more >
Browserify
Browserify lets you require('modules') in the browser by bundling up all of your dependencies. Install Documentation · Source Code · Help + Articles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found