|
167 | 167 | :emit-constants :ups-externs :ups-foreign-libs :ups-libs :warning-handlers :preloads
|
168 | 168 | :browser-repl :cache-analysis-format :infer-externs :closure-generate-exports :npm-deps
|
169 | 169 | :fn-invoke-direct :checked-arrays :closure-module-roots :rewrite-polyfills :use-only-custom-externs
|
170 |
| - :watch :watch-error-fn :watch-fn :install-deps}) |
| 170 | + :watch :watch-error-fn :watch-fn :install-deps :process-shim}) |
171 | 171 |
|
172 | 172 | (def string->charset
|
173 | 173 | {"iso-8859-1" StandardCharsets/ISO_8859_1
|
|
1955 | 1955 | (format ":nodejs target with :none optimizations requires a :main entry")))
|
1956 | 1956 |
|
1957 | 1957 | (defn check-preloads [{:keys [preloads optimizations] :as opts}]
|
1958 |
| - (when (and (some? preloads) (not= optimizations :none)) |
| 1958 | + (when (and (some? preloads) |
| 1959 | + (not= preloads '[process.env]) |
| 1960 | + (not= optimizations :none)) |
1959 | 1961 | (binding [*out* *err*]
|
1960 | 1962 | (println "WARNING: :preloads should only be specified with :none optimizations"))))
|
1961 | 1963 |
|
|
2038 | 2040 | (update opts :modules
|
2039 | 2041 | #(ensure-cljs-base-module % opts)))
|
2040 | 2042 |
|
| 2043 | +(defn shim-process? [opts] |
| 2044 | + (not (false? (:process-shim opts)))) |
| 2045 | + |
2041 | 2046 | (defn add-implicit-options
|
2042 | 2047 | [{:keys [optimizations output-dir]
|
2043 | 2048 | :or {optimizations :none
|
2044 | 2049 | output-dir "out"}
|
2045 | 2050 | :as opts}]
|
2046 | 2051 | (let [opts (cond-> opts
|
2047 |
| - (:closure-defines opts) |
2048 |
| - (assoc :closure-defines |
2049 |
| - (into {} |
2050 |
| - (map (fn [[k v]] |
2051 |
| - [(if (symbol? k) (str (comp/munge k)) k) v]) |
2052 |
| - (:closure-defines opts)))) |
| 2052 | + (shim-process? opts) |
| 2053 | + (-> (update-in [:preloads] (fnil conj []) 'process.env) |
| 2054 | + (cond-> |
| 2055 | + (not= :none optimizations) |
| 2056 | + (update-in [:closure-defines 'process.env/NODE_ENV] (fnil str "production")))) |
| 2057 | + |
| 2058 | + (or (:closure-defines opts) (shim-process? opts)) |
| 2059 | + (update :closure-defines |
| 2060 | + (fn [defines] |
| 2061 | + (into {} |
| 2062 | + (map (fn [[k v]] |
| 2063 | + [(if (symbol? k) (str (comp/munge k)) k) v]) |
| 2064 | + defines)))) |
2053 | 2065 | (:browser-repl opts)
|
2054 | 2066 | (update-in [:preloads] (fnil conj []) 'clojure.browser.repl.preload))
|
2055 | 2067 | {:keys [libs foreign-libs externs]} (get-upstream-deps)
|
|
0 commit comments