можно ли загрузить модули reasonml es6 без упаковщика - PullRequest
0 голосов
/ 19 февраля 2020

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

Это почти работает, но компилятор 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 Ответ

0 голосов
/ 28 февраля 2020

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

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

...