[英]what is a preferred way to include bootstrap jQuery etc libs into project?
[英]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}}
}
}
我从这里得到了编译文件,我在项目中复制了该文件。 虽然经过所有这些更改后,我仍然无法在组件中使用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
属性,因为我不确定包。 另外我不确定我是否需要做一些: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.