• ReasonML
    • ReasonML/BuckleScript
      • ReasonReact
    • 帮助我们改善文档

    ReasonML

    支持扩展类型: ml, re

    ReasonML/BuckleScript

    ReasonML在BuckleScript 的帮助下将 OCaml 编译为 JavaScript。通过安装依赖和创建bsconfig.json文件使用 ReasonML。

    1. $ yarn add bs-platform --dev
    1. // bsconfig.json
    2. // from https://github.com/BuckleScript/bucklescript/blob/master/jscomp/bsb/templates/basic-reason/bsconfig.json
    3. {
    4. "name": "whatever",
    5. "sources": {
    6. "dir": "src",
    7. "subdirs": true
    8. },
    9. "package-specs": {
    10. "module": "commonjs",
    11. "in-source": true
    12. },
    13. "suffix": ".bs.js",
    14. "bs-dependencies": [],
    15. "warnings": {
    16. "error": "+101"
    17. },
    18. "namespace": true,
    19. "refmt": 3
    20. }
    1. <!-- index.html -->
    2. <!DOCTYPE html>
    3. <html>
    4. <body>
    5. <script src="./src/index.re"></script>
    6. </body>
    7. </html>
    1. /* src/index.re */
    2. print_endline("Hello World");

    ReasonReact

    ReasonReact 通过 ReasonML 构建 React。当然也能在 Parcel 中使用:

    1. $ yarn add react react-dom reason-react
    1. // bsconfig.json
    2. {
    3. "name": "whatever",
    4. + "reason": {
    5. + "react-jsx": 3
    6. + },
    7. "sources": {
    8. "dir": "src",
    9. "subdirs": true
    10. },
    11. "package-specs": {
    12. "module": "commonjs",
    13. "in-source": true
    14. },
    15. "suffix": ".bs.js",
    16. "bs-dependencies": [
    17. + "reason-react"
    18. ],
    19. "warnings": {
    20. "error": "+101"
    21. },
    22. "namespace": true,
    23. "refmt": 3
    24. }
    1. <!-- index.html -->
    2. <html>
    3. <body>
    4. + <div id="app"></div>
    5. <script src="./src/index.re"></script>
    6. </body>
    7. </html>
    1. /* src/Greeting.re */
    2. [@react.component]
    3. let make = (~name) => {
    4. <div> {React.string("Hello! " ++ name)} </div>;
    5. };
    1. /* src/index.re */
    2. ReactDOMRe.renderToElementWithId(<Greeting name="Parcel" />, "app");

    帮助我们改善文档

    如果有遗漏或者不清楚的地方,请在本站的仓库 提交issue 或者 编辑此页面.