- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有一个 cljs
包含以下内容的文件:
(ns foo)
(defn add [x y]
(+ x y))
clj -m cljs.main -c foo
goog.require
)。我可以将目标设置为
none
与
-t
标志(与浏览器或节点相反),并且......不能解决这个问题。将其设置为
node
也不能解决问题:否
index.js
(它在 Java 中称为 main),没有
module.exports = blah blah
.似乎它面向独立的全节点应用程序,而不是库。
--help
错误的?
最佳答案
这假设您已经安装了 ClojureScript 和 Node.js
鉴于:
math101
|-- package.json
|-- src
| `-- com
| `-- example
| `-- math.cljs
{
"name": "math101",
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
"shadow-cljs": "^2.8.52",
"source-map-support": "^0.5.13"
}
}
dist/index.js
- 这将包含我们转换为 JavaScript shadow-cljs
- 我们需要的构建(和依赖管理)工具source-map-support
- Required to run ClojureScript on Node.js (ns com.example.math)
(defn add [x y]
(+ x y))
math101
的根目录下运行
yarn shadow-cljs init
.
shadow-cljs.edn
的文件。使用一些默认设置:
;; shadow-cljs configuration
{:source-paths
["src/dev"
"src/main"
"src/test"]
:dependencies
[]
:builds
{}}
{:source-paths
["src"]
:dependencies
[]
:builds
{}}
;; shadow-cljs configuration
{:source-paths
["src"]
:dependencies
[]
:builds
{:math101 {:target :node-library
:output-to "dist/index.js"
:exports-var com.example.math/add}}}
:math101
- 这是我们稍后将使用的构建 ID :target :node-library
- 这告诉 shadow-cljs
你打算创作一个图书馆:output-to "dist/index.js"
- 您打算发布的代码:exports-var com.example.math/add
- 您打算发布的函数的“完全限定名称”。这将产生一个默认导出。 The :target :node-library emits code that can be used (via require) as a standard node library, and is useful for publishing your code for re-use as a compiled Javascript artifact.
:npm-module
目标可用但到目前为止
:node-library
已为我检查了所有框。
yarn shadow-cljs compile math101
.
shadow-cljs
会下载一堆东西。最终它会完成,当它完成时......
$ node
> var add = require('./dist')
> add(40, 2)
42
subtract
:
(ns com.example.math)
(defn add [x y]
(+ x y))
(defn subtract [x y]
(- x y))
;; shadow-cljs configuration
{:source-paths
["src"]
:dependencies
[]
:builds
{:math101 {:target :node-library
:output-to "dist/index.js"
:exports {:add com.example.math/add
:subtract com.example.math/subtract}}}}
yarn shadow-cljs compile math101
再次,当它完成时:
$ node
> var math101 = require('./dist')
> math101.add(40, 2)
42
> math101.subtract(44, 2)
42
shadow-cljs compile
生成非生产代码(即它没有被缩小,死代码没有被删除 AFAIK 并且 Google Closure 还没有运行任何优化)。
shadow-cljs release
但你可能想在之前调整你的构建配置。
关于clojurescript - 如何在 ClojureScript 中编写不可知的 JavaScript 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52894430/
如何从 clojurescript 程序中获取我所在的 Clojurescript 命名空间?我想这样做确实提供了某些调试信息(它只需要在开发模式下工作) 最佳答案 命名空间在 ClojureScri
我正在考虑使用 ClojureScript 构建一个网站。在客户端和服务器端都编写 ClojureScript 是否有意义,就像 node.js 一样? 最佳答案 这是可能的,但绝对没有理由不在服务器
我正在与Om合作,但我不完全理解以下表达式: (.. e -target -checked) 在这里,“ e”是一个JavaScript事件,“-target -checked”是一种访问属性的方式
我想在 ClojureScript 中前向声明一个函数。种 (defn a [] (b)) ... (defn b [] ...) 我觉得在用法(b)前面放一个(def b nil)是个什么样的作品,
我想在 ClojureScript 中前向声明一个函数。种 (defn a [] (b)) ... (defn b [] ...) 我觉得在用法(b)前面放一个(def b nil)是个什么样的作品,
我不知道像 this 这样的“自托管”clojurescript 实现如何和 this被实现。 但是,鉴于 clojurescript 编译器是用 clojure 编写的并将 clojure 编译为
考虑以下假设的无意义的 ClojureScript 函数: (defn tmp [] (def p 0) (set! p (inc p)) (set! p (inc p)) (set!
我在生产构建部分遇到问题 ClojureScript quickstart .具体来说,当我运行时:java -cp "cljs.jar;src" clojure.main release.clj我得
我正在尝试使用 defmacro在 ClojureScript 中,但出现控制台错误: TypeError: 'undefined' is not an object (evaluating 'crd
我正在寻找一种在 clojureScript 中根据字符串名称调用函数的方法。 就像是: (call "my-fun" args) 欢迎任何帮助 最佳答案 一个应该有效的非常hackish的解决方案:
在 Ubuntu 10.04.1 LTS 上的 FireFox 5.0 中运行的 ClojureScript 程序中,当抛出异常时,我得到一条神秘的线。 '错误:没有为类型对象定义协议(protoco
我正在努力工作 FormidableLabs/radium · GitHub与 reagent-project/reagent · GitHub ,但我已经走到了死胡同。 我能够通过“破解”试剂功能使
是否可以将 Google Closure Templates 与 Clojurescript 一起使用? 我环顾四周,但没有找到任何有关此的信息。 最佳答案 由于 Soy 模板已编译为 JavaScr
我想从 clojurescript 设置 element.style.height 属性,但不幸的是这段代码失败了: (set! (-> (sel1 tr :.ragslide) .-style .-
我正在使用 ClojureScript 编写一些原子(编辑器)包。我遇到了依赖加载问题。 编译后的 ClojureScript 生成如下文件 (main.js): goog.addDependency
我正在为 clojurescript 库编写一些 cljs.test 测试,并且有一些我想加载的 JSON 测试数据。 我不确定我可以使用什么函数来从项目的本地文件加载数据。 我正在使用 lein-d
我有一个从 Leiningen 启动的 ClojureScript 应用程序。我如何在应用程序启动时将环境变量传递给应用程序(可能是它构建时) 最佳答案 有两个构建时间选项: 使用宏 CLJS 宏是
如何在 ClojureScript 中获取时间戳,类似于 Unix 的时间戳,即表示当前时间和日期的单个数字,作为数字。我知道: if (!Date.now) { Date.now = fun
我需要使用 ClojureScript 打开一个新选项卡。 (js/window.open "http://localhost/go/somewhere") 我收到以下错误:未捕获类型错误:windo
我已经阅读了 David Nolen 的基本 Om 教程,但我仍然对应用程序状态和组件本地状态之间的区别感到有些困惑。当引用游标时,它是否也引用了其中之一或两者? 最佳答案 据我了解: 应用程序状态是
我是一名优秀的程序员,十分优秀!