HLJS compiled from website does not work with browserify
See original GitHub issueThe compiled packs tag on:
hljs.registerLanguage(....)
to the build code, for each language you ask for. However, hljs
is undefined at this point if we are using browserify (commonJS) to require
it. Can be fixed specifically in this case by adding var hljs = module.exports
before the registerLanguage lines. Personally I’d fix by returning the hljs object from the initial function that decided where to put it, and using the returned ref when registerLanguage-ing
Issue Analytics
- State:
- Created 9 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
How to use highlight.js
You can run highlighting inside a web worker to avoid freezing the browser window while dealing with very big chunks of code. In...
Read more >Home / Analyzing browserify bundles to minimize JavaScript ...
The problem was that while core of highlight.js is small, it supports 168 languages and doing import 'highlight.js' would bundle all of.
Read more >Browserify - Bundle loads, but doesn't work afterwards
The problem is that after the code gets compiled the function isn't attached to the window object but instead is executed within a...
Read more >brief-highlightjs | Yarn - Package Manager
Highlight.js is a syntax highlighter written in JavaScript. It works in the browser as well as on the server. It works with pretty...
Read more >Properly shim AngularJS applications using Browserify
Pretty simple huh? But as you might expect, this doesn't work. Open index.html in a web browser and take a look at the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The full npm package is quite big indeed.
In my project, I create a trimmed copy of
/node_modules/highlight.js/lib/index.js
. This allows me to choose a potion of all supported languages.Then require this one instead of the npm package.
My production bundle file decreases for about 480KB.
Yea, i’m just doing this along with all my other requires.
Not really hacking, just skipping the include every language file. Works well.