可以在没有bundler的情况下加载reasonml es6模块



我正在尝试使用我的VSCODDE肝脏服务器:https://github.com/ritwickdey/vscode-live-server对于不必运行的开发(parceljs是我的最爱,因为它有热加载,但它在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在中创建了这个

应用程序.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";

现在,如果进口是从/节点模块/*文件夹,我认为所有的都可以工作

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"
]
}

看起来BuckleScript不能用es6-global导入外部JavaScript模块,包括React。GitHub的相关问题在这里。

问题是BuckleScript目前无法知道"react"应该解析到的JavaScript文件的路径。BuckleScript知道它编译的模块的路径,所以它们工作得很好。但它对外部事物一无所知,所以它按原样输出它们的路径。

相关内容

  • 没有找到相关文章

最新更新