我正在尝试使用 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 得到了编译后的文件我已经在我的项目中复制了。虽然在所有这些更改之后,我仍然无法在我的组件中使用 DragDropContext
或 Droppable
。
在我的组件中,我将它们声明如下
(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/