javascript - 在 clojurescript 项目中包含外部库

标签 javascript reactjs clojurescript reagent react-dnd

我正在尝试使用 react-beautiful-dnd在我的新 ClojureScript 和 Reagent 中应用。根据博客here ,它说我需要在我的 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}}



            }
   }

我从 here 得到了编译后的文件我已经在我的项目中复制了。虽然在所有这些更改之后,我仍然无法在我的组件中使用 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 属性,因为我不确定 package.此外,我不确定是否需要在我的 core.cljs 组件文件中执行一些 :require

最佳答案

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

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

关于javascript - 在 clojurescript 项目中包含外部库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46905604/

相关文章:

javascript - 巴别塔似乎不起作用

css - 如何制作 svg RTL

reactjs - 如何部署/连接 React/Flask-RESTful 应用程序?

reactjs - Enzyme/Karma/Webpack/Jasmine/React 测试不起作用

javascript - 交付 ClojureScript 桌面应用程序的最正常方式是什么

reactjs - 试剂:component-did-mount

javascript - 如何在 ClojureScript 中使用方法和构造函数创建 JS 对象

javascript - 如何在 AngularJS 中与服务进行双向数据绑定(bind)?

函数中的Javascript变量更改全局变量

javascript - 禁用提交按钮,直到两个输入都不为空