Andreas Steffan
Andreas Steffan

Reputation: 6159

How/Can I exclude inherited foreign libs from ClojureScript compiler output?

I am using reagent 0.5.0 which depends on cljsjs/react. The latter comes with the following deps.cljs

{:foreign-libs [{
 :file "cljsjs/development/react.inc.js",
 :file-min "cljsjs/production/react.min.inc.js",
 :provides ["cljsjs.react"]}],
 :externs ["cljsjs/common/react.ext.js"]}

which makes the React's JavaScript end up in the compiler output.

I would like to prevent this from happening, because I also want to use React in plain JavaScript pages.

Besides, reagent/core.cljs has a :require [cljsjs.react] directive (To force the inclusion?) so the dependency cannot simply be omitted.

Is there a way to prevent React from ending up in the compiler output?

Upvotes: 1

Views: 757

Answers (1)

Walton Hoops
Walton Hoops

Reputation: 864

From the Reagent Readme (https://github.com/reagent-project/reagent):

If you want the version of React with addons, you'd use something like this instead:

[reagent "0.5.0" :exclusions [cljsjs/react]]
[cljsjs/react-with-addons "0.12.2-4"]

If you want to use your own build of React (or React from a CDN), you have to use :exclusions variant of the dependency, and also provide a file named "cljsjs/react.cljs", containing just (ns cljsjs.react), in your project.

So, just use the :exclusions option in your dependencies, and provide your own cljsjs/react namespace and your good to go. It's up to you at that point to ensure React is loaded before Reagent however.

Upvotes: 1

Related Questions