简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM