文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
ReasonML
支援的副档名:ml
及 re
ReasonML/BuckleScript
ReasonML 透过 BuckleScript 将 Ocaml 编译成 JavaScript。
安装相依套件及建立 bsconfig.json
后即可开始使用 ReasonML:
$ yarn add bs-platform --dev
// bsconfig.json
// from https://github.com/BuckleScript/bucklescript/blob/master/jscomp/bsb/templates/basic-reason/bsconfig.json
{
"name": "whatever",
"sources": {
"dir": "src",
"subdirs": true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [],
"warnings": {
"error": "+101"
},
"namespace": true,
"refmt": 3
}
<!-- index.html -->
<!doctype html>
<html>
<body>
<script src="./src/index.re"></script>
</body>
</html>
/* src/index.re */
print_endline("Hello World");
ReasonReact
ReasonReact 让你可在 ReasonML 中使用 React:
$ yarn add react react-dom reason-react
// bsconfig.json
{
"name": "whatever",
+ "reason": {
+ "react-jsx": 2
+ },
"sources": {
"dir": "src",
"subdirs": true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
+ "reason-react"
],
"warnings": {
"error": "+101"
},
"namespace": true,
"refmt": 3
}
<!-- index.html -->
<html>
<body>
+ <div></div>
<script src="./src/index.re"></script>
</body>
</html>
/* src/Greeting.re */
let component = ReasonReact.statelessComponent("Greeting");
let make = (~name, _children) => {
...component,
render: _self => <div> (ReasonReact.string("Hello! " ++ name)) </div>,
};
/* src/index.re */
ReactDOMRe.renderToElementWithId(<Greeting name="Parcel" />, "app");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论