Fork me on GitHub
#clojurescript
<
2022-07-01
>
john13:07:57

Yeah, you should be able to pull that off with tag readers

john13:07:33

well, as long as you can target the same env from two different build ids, I don't recall. But you can def use tag readers to conditionally require things

Alex Miller (Clojure team)13:07:06

you can do that, but you can't define new features (like :build-1 or :other-build)

john14:07:11

Yeah, I'm not sure what the ask is there. I one time toyed around with lazy requires, where you defined whether to require lazily loaded modules via clojure-defines, with something like:

(defn get-req-form [form]
  (->> form (filter #(and (list? %) (= :require (first %)))) first))

;; maps to #lz/ns
(defn rq [[lazy-form orig-form]]
  (if (:lz/lazy? (get-env))
    orig-form
    (let [req-form (get-req-form orig-form)
          new-reqs (-> lazy-form rest set)
          old-reqs (-> req-form rest set)
          not-reqs (->> orig-form (filter #(not= req-form %)))]
      (concat not-reqs
        (list (concat (list :require)
                (into old-reqs new-reqs)))))))
And then in some namespace def you could do something like:
#lz/ns
  [(:require [com.acme.eager :as eager])
   (ns lz.suspense.reagent.example
        (:require
         [lz.suspense.reagent]
         [cljs.loader :as loader]
         [goog.dom :as gdom]
         [reagent.core :as reagent :refer [atom]]))]
(Something like that - it's been a while) Kinda ugly though

john14:07:09

Where get-env would get you your info out of closure-defines