-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HLJS compiled from website does not work with browserify #712
Comments
The way we maintain the library is that we keep the source code packaging-agnostic and then have a few specific formats in which we build the library for different targets. The website serves the browser-specific build intended to be linked by a |
It would be nice to have some additional |
@kelunik we already provide hosted browser packages for that. |
@isagalaev You mean those on highlightjs.org? |
The thing is, everyone really likes organizing their workflow in their own way. We can't (and don't want to) support every combination imaginable. We encourage everyone to support third-party packages if what we provide doesn't fit the bill. |
I totally agree that everybody has their own workflow here, but I think it's worth having two standard distributions for npm, one with full language support and another with common language support, so you don't have to include a common node build for browserify in every repo. |
For what it's worth to anyone else bumping into this issue, you can make the web builds of hljs load via browserify by adding |
The full npm package is quite big indeed. In my project, I create a trimmed copy of // This is a trimmed version of highlight.js main file
// See '/node_modules/highlight.js/lib/index.js' for all supported languages
// For more details, visit https://highlightjs.org/
var hljs = require('highlight.js/lib/highlight')
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'))
hljs.registerLanguage('css', require('highlight.js/lib/languages/css'))
hljs.registerLanguage('javascript', require('highlight.js/lib/languages/javascript'))
module.exports = hljs Then require this one instead of the npm package. // var hljs = require('highlight.js')
var hljs = require('../assets/scripts/hljs.trimmed') My production bundle file decreases for about 480KB. |
Yea i do a similar thing to just include specific languages i want. Works well |
Did you guys read http://highlightjs.readthedocs.io/en/latest/building-testing.html ? You don't need to hack any files, you can just build whatever you like. |
That's true. However, on the other hand my Or, maybe I could include this repo as submodule, then add a |
Yea, i'm just doing this along with all my other requires.
Not really hacking, just skipping the include every language file. Works well. |
PS, this library is amazing...thanks for maintaining it |
I'm using webpack targeting the browser and I wanted my dependencies sorted out on the server. I couldn't the website generated In one file put:
And then to load, you can load the above and go through each key in the exported object and register that as a language.
Works great on my blog and all I have to do is change an array and run my build and Im good to go! |
The compiled packs tag on:
to the build code, for each language you ask for. However,
hljs
is undefined at this point if we are using browserify (commonJS) torequire
it. Can be fixed specifically in this case by addingvar 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-ingThe text was updated successfully, but these errors were encountered: