можно ли загружать модули reasonml es6 без сборщика

Я пытаюсь использовать свой сервер печени VSCODDE: https://github.com/ritwickdey/vscode-live-server для разработки без необходимости запускать (parceljs был бы моим любимым, так как у него горячая загрузка, но возникают проблемы с разумом ml).

Это почти работает, но компилятор bucklescript ожидает, что узлы-модули будут на пути, и похоже, что сборщики найдут их, но не в том случае, если загрузка выполняется таким образом:

es5index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset=utf-8>
  <link rel=stylesheet href="./style.css">
  <title>Web Data Client</title>
  <script src="../src/client/App.bs.js" type=module></script>
</head>

<body>
  <div id="index"></div>
</body>

</html>

Это ошибка, которую я получаю:

ncaught TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".

чего и следовало ожидать, поскольку BSB создал это в

App.bs.js

import * as $$Array from "./../../node_modules/bs-platform/lib/es6/array.js";
import * as Block from "./../../node_modules/bs-platform/lib/es6/block.js";
import * as Curry from "./../../node_modules/bs-platform/lib/es6/curry.js";
import * as React from "react";
import * as Glamor from "./../../node_modules/bs-glamor/src/glamor.js";
import * as Js_exn from "./../../node_modules/bs-platform/lib/es6/js_exn.js";
import * as Js_dict from "./../../node_modules/bs-platform/lib/es6/js_dict.js";
import * as Js_json from "./../../node_modules/bs-platform/lib/es6/js_json.js";
import * as ReactDOMRe from "./../../node_modules/reason-react/src/ReactDOMRe.js";
import * as Caml_option from "./../../node_modules/bs-platform/lib/es6/caml_option.js";
import * as ReasonReact from "./../../node_modules/reason-react/src/ReasonReact.js";
import * as Editor$Webdataclient from "./Editor.bs.js";
import * as Loader$Webdataclient from "./Loader.bs.js";
import * as Mutations$Webdataclient from "./Mutations.bs.js";

теперь, если бы импорт был из папки../node-modules/*, я думаю, что все будет работать

файл bsconfig.json:

// This is the configuration file used by BuckleScript's build system bsb. 
// Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
{
  "name": "webdataclient",
  "version": "0.1.0",
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    }
  ],
  "package-specs": {
    "module": "es6-global",
    "in-source": true
  },
  "suffix": ".bs.js",
  "namespace": true,
  "reason": {
    "react-jsx": 2
  },
  "refmt": 3,
  "ppx-flags": [
    "graphql_ppx/ppx"
  ],
  "bs-dependencies": [
    "reason-react",
    "bs-fetch",
    "bs-glamor"
  ]
}

1 ответ

Не похоже, что BuckleScript может импортировать внешние модули JavaScript с es6-global, включая React. Соответствующая проблема GitHub находится здесь.

Проблема в том, что BuckleScript в настоящее время не может узнать путь к файлу JavaScript, который "react"предполагается разрешить. BuckleScript знает пути к компилируемым модулям, поэтому они работают нормально. Но он ничего не знает о внешних объектах, поэтому выводит их пути как есть.

Другие вопросы по тегам