Skip to content

Commit

Permalink
Fix build performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
superstructor committed May 21, 2022
1 parent 14de40c commit 704a66d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,16 @@
## Unreleased

#### Changed

- BREAKING: Only include `"hightlight.js/lib/core"` to fix build performance issues
caused by previously loading all languages. Now only Clojure support is
registered by default. If you are using any other language, you now need to
explicitly require and register it! E.g.
```clojure
(require ["highlight.js/lib/languages/rust" :as rust])
(re-highlight/register-language "rust" rust)
```

## 1.1.0 (2021-07-14)

#### Changed
Expand Down
22 changes: 12 additions & 10 deletions README.adoc
Expand Up @@ -14,7 +14,7 @@ image:https://img.shields.io/github/license/superstructor/re-highlight?style=for
= Reagent wrapper for Highlight.js

A simple Reagent wrapper around the link:https://highlightjs.org/[Highlight.js] library, with no dependencies except Highlight.js itself
link:https://www.npmjs.com/package/highlight.js[via npm (for shadow-cljs)] or link:https://github.com/cljsjs/packages/tree/master/highlight[via cljsjs].
link:https://www.npmjs.com/package/highlight.js[via npm (for shadow-cljs)].

== Quick Start

Expand All @@ -25,14 +25,8 @@ image:https://img.shields.io/clojars/v/superstructor/re-highlight?style=for-the-

Requires that you have reagent as a dependency of your project: image:https://img.shields.io/clojars/v/reagent?style=for-the-badge&logo=clojure&logoColor=fff["Clojars Project", link="https://clojars.org/reagent"]

If you use shadow-cljs, the `highlight.js` npm library dependency will be
pulled automatically via `src/deps.cljs` `:npm-deps`.

If you use another build system, you will probably need to add the following
cljsjs dependency to your project:
image:https://img.shields.io/clojars/v/cljsjs/highlight?style=for-the-badge&logo=clojure&logoColor=fff["Clojars Project", link="https://clojars.org/cljsjs/highlight"]

Cljsjs is not included as a transitive dependency because it lags behind the npm release, so including it here would mean that this project depended on two different versions of Highlight.js. Cljsjs support is not a priority since shadow-cljs is the way to go these days, so code-wise it is compatible but consumers who want it have the cljsjs support need to add the dependency themselves.
The `highlight.js` npm library dependency will be
pulled in automatically by shadow-cljs via `src/deps.cljs` `:npm-deps`.

=== Step 2. Add Highlight.js Theme

Expand All @@ -53,11 +47,19 @@ Add a Highlight.js stylesheet to your `index.html` or equivalent; e.g.:
{:language "clojure"}
"(defn fibo-recursive [n]\n (if (or (= n 0) (= n 1))\n n\n (+ (fibo-recursive (- n 1)) (fibo-recursive (- n 2)))))"]]])

=== Step 4. Optional. Add non-Clojure Language Support

Only Clojure support is registered by default. If you are using any other language, you need to explicitly require
and register it! E.g.

(require ["highlight.js/lib/languages/rust" :as rust])
(re-highlight/register-language "rust" rust)

== License

The MIT License (MIT)

Copyright (c) 2019-2021 Isaac Johnston
Copyright (c) 2019-2022 Isaac Johnston

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 8 additions & 8 deletions project.clj
Expand Up @@ -3,22 +3,22 @@
:url "https://github.com/superstructor/re-highlight.git"
:license {:name "MIT"}

:dependencies [[org.clojure/clojure "1.10.3" :scope "provided"]
[org.clojure/clojurescript "1.10.879" :scope "provided"
:dependencies [[org.clojure/clojure "1.11.1" :scope "provided"]
[org.clojure/clojurescript "1.11.54" :scope "provided"
:exclusions [com.google.javascript/closure-compiler-unshaded
org.clojure/google-closure-library
org.clojure/google-closure-library-third-party]]
[thheller/shadow-cljs "2.15.2" :scope "provided"]
[reagent "1.1.0" :scope "provided"]
[thheller/shadow-cljs "2.19.0" :scope "provided"]
[reagent "1.1.1" :scope "provided"]
[re-com "2.13.2" :scope "provided"]]

:plugins [[day8/lein-git-inject "0.0.15"]
[lein-shadow "0.4.0"]
[lein-shell "0.5.0"]]
:plugins [[day8/lein-git-inject "0.0.15"]
[lein-shadow "0.4.0"]
[lein-shell "0.5.0"]]

:middleware [leiningen.git-inject/middleware]

:profiles {:dev {:dependencies [[binaryage/devtools "1.0.3"]]
:profiles {:dev {:dependencies [[binaryage/devtools "1.0.6"]]
:plugins [[com.github.liquidz/antq "RELEASE"]
[lein-pprint "1.3.2"]]}}

Expand Down
19 changes: 13 additions & 6 deletions src/re_highlight/core.cljs
@@ -1,11 +1,18 @@
(ns re-highlight.core
(:require
[goog.object :as gobj]
[reagent.core :as r]
[reagent.dom :as rdom]
[highlight.js :as highlight-js]))
[goog.object :as gobj]
[reagent.core :as r]
[reagent.dom :as rdom]
["highlight.js/lib/core" :as hljs]
["highlight.js/lib/languages/clojure" :as clojure]))

(def highlight-element (gobj/get highlight-js "highlightElement"))
(defn register-language
[label js-obj]
(.registerLanguage hljs label js-obj))

(register-language "clojure" clojure)

(def highlight-element (gobj/get hljs "highlightElement"))

(defn did-mount
[this]
Expand All @@ -15,7 +22,7 @@
(defn did-update
[this old-argv old-state snapshot]
(when-let [el (gobj/get (rdom/dom-node this) "firstChild")]
(-> (gobj/get highlight-js "initHighlighting")
(-> (gobj/get hljs "initHighlighting")
(gobj/set "called" false))
(highlight-element el)))

Expand Down

0 comments on commit 704a66d

Please sign in to comment.