首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在clojurescript项目中包含外部库

在clojurescript项目中包含外部库
EN

Stack Overflow用户
提问于 2017-10-24 16:27:23
回答 2查看 910关注 0票数 4

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

我已经进行了如下配置

代码语言:javascript
复制
  :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}}



            }
   }

我从here获得了编译后的文件,并将其复制到我的项目中。尽管经过所有这些更改,我仍然不能在我的组件中使用DragDropContextDroppable

我在我的组件中声明了它们,如下所示

代码语言:javascript
复制
(def DragDropContext (reagent/adapt-react-class js/DragDropContext))
(def Droppable (reagent/adapt-react-class js/Droppable))

有没有人能帮我弄明白我到底做错了什么?我收到如下错误

代码语言:javascript
复制
Uncaught ReferenceError: DragDropContext is not defined
    at core.cljs?rel=1508832729388:11
(anonymous) @ core.cljs?rel=1508832729388:11

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

EN

回答 2

Stack Overflow用户

发布于 2018-02-28 04:40:33

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

代码语言:javascript
复制
(def DragDropContext (reagent/adapt-react-class js/ReactBeautifulDnd.DragDropContext))
(def Droppable (reagent/adapt-react-class js/ReactBeautifulDnd.Draggable))
票数 2
EN

Stack Overflow用户

发布于 2017-10-24 17:12:21

你需要添加:provides (你可以选择任何想要的ns名称,例如react-beautiful-dnd),然后require它,这样它就被加载了。因为它依赖于React,所以您应该在requires中指定它(例如,如果您包含React作为cljsjs.react依赖项,则将其指定为CLJSJS ):

代码语言:javascript
复制
[{:file "src/cljs/react-beautiful-dnd/react-beautiful-dnd.js"
  :provides ["react-beautiful-dnd"]
  :requires ["cljsjs.react"]}]

在您的命名空间中:

代码语言:javascript
复制
(ns my.ns
  (:require
    [cljsjs.react]
    [react-beautiful-dnd]))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46905604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档