繁体   English   中英

包括clojurescript项目中的外国文库

[英]include foreign libs in clojurescript project

我想在我的新ClojureScript和Reagent应用程序中使用react-beautiful-dnd 根据这里的博客,它说我需要在我的project.clj文件中使用:foreign-libs包含该文件。

我已将其配置如下

  :cljsbuild
  {:builds {:min
            {:source-paths ["src/cljs" "src/cljc" "env/prod/cljs"]
             :compiler
             {:output-to        "target/cljsbuild/public/js/app.js"
              :output-dir       "target/cljsbuild/public/js"
              :source-map       "target/cljsbuild/public/js/app.js.map"
              :optimizations :advanced
              :foreign-libs [{:file "src/cljs/react-beautiful-dnd/react-beautiful-dnd.js"}]
              :pretty-print  false}}
            :app
            {:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"]
             :figwheel {:on-jsload "toka.core/mount-root"}
             :compiler
             {:main "toka.dev"
              :asset-path "/js/out"
              :output-to "target/cljsbuild/public/js/app.js"
              :output-dir "target/cljsbuild/public/js/out"
              :source-map true
              :optimizations :none
              :pretty-print  true}}



            }
   }

我从这里得到了编译文件,我在项目中复制了该文件。 虽然经过所有这些更改后,我仍然无法在组件中使用DragDropContextDroppable

在我的组件中,我已将它们声明如下

(def DragDropContext (reagent/adapt-react-class js/DragDropContext))
(def Droppable (reagent/adapt-react-class js/Droppable))

谁能帮助我理解我在这里做错了什么? 我收到的错误如下

Uncaught ReferenceError: DragDropContext is not defined
    at core.cljs?rel=1508832729388:11
(anonymous) @ core.cljs?rel=1508832729388:11

注意:我没有在foreign-libs添加任何provide属性,因为我不确定包。 另外我不确定我是否需要做一些:require在我的core.cljs组件文件中需要。

您需要添加:provides (您可以选择您想要的任何名称,例如react-beautiful-dnd ),然后require它以便加载它。 因为它依赖于反应,你应该指定它requires (如cljsjs.react ,如果你提供作出反应,CLJSJS依赖):

[{:file "src/cljs/react-beautiful-dnd/react-beautiful-dnd.js"
  :provides ["react-beautiful-dnd"]
  :requires ["cljsjs.react"]}]

在您的命名空间中:

(ns my.ns
  (:require
    [cljsjs.react]
    [react-beautiful-dnd]))

我遇到了同样的问题并找到了解决方案。 组件被放在一个单独的命名空间中,因此必须像这样引用:

(def DragDropContext (reagent/adapt-react-class js/ReactBeautifulDnd.DragDropContext))
(def Droppable (reagent/adapt-react-class js/ReactBeautifulDnd.Draggable))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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