Skip to content

Instantly share code, notes, and snippets.

@markusbergh
Created January 10, 2018 09:51
Show Gist options
  • Save markusbergh/aae07f8720ea8da5a4b2ae526ea2280b to your computer and use it in GitHub Desktop.
Save markusbergh/aae07f8720ea8da5a4b2ae526ea2280b to your computer and use it in GitHub Desktop.
Highlight.js with tree shaking
// Core import
import highlightjs from 'highlight.js/lib/highlight'
// Languages import
import javascript from 'highlight.js/lib/languages/javascript'
import bash from 'highlight.js/lib/languages/bash'
import yaml from 'highlight.js/lib/languages/yaml'
// Register languages
highlightjs.registerLanguage('javascript', javascript)
highlightjs.registerLanguage('bash', bash)
highlightjs.registerLanguage('yaml', yaml)
...
@jmont96
Copy link

jmont96 commented May 20, 2024

Change this to and it will work:

import hljs from 'highlight.js/lib/core';
import typescript from 'highlight.js/lib/languages/typescript';
import 'highlight.js/styles/github.css';

hljs.registerLanguage('typescript', typescript);

Only change is changing import highlightjs from 'highlight.js/lib/highlight' => import hljs from 'highlight.js/lib/core';

@superjose
Copy link

Change this to and it will work:

import hljs from 'highlight.js/lib/core';
import typescript from 'highlight.js/lib/languages/typescript';
import 'highlight.js/styles/github.css';

hljs.registerLanguage('typescript', typescript);

Only change is changing import highlightjs from 'highlight.js/lib/highlight' => import hljs from 'highlight.js/lib/core';

Beautiful! This worked wonders!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment