我想在我的浏览器中将此文件作为 es 模块。HelloApp.tsx
import React from "react";
import { render } from "react-dom";
function HelloApp(props: any): React.ReactElement {
return <div>Greetings</div>
}
render(
<HelloApp />,
document.getElementById("app")
);
我在跑npx esbuild ./**/*.tsx --outdir=esbuilt --format=esm
输出:
import React from "react";
import {render} from "react-dom";
function HelloApp(props) {
return /* @__PURE__ */ React.createElement("div", null, "I'm a component");
}
render(/* @__PURE__ */ React.createElement(HelloApp, null), document.getElementById("app"));
浏览器无法使用这些导入。理想情况下,路径将类似于import React from "/scripts/react.js"
你如何告诉 esbuild 编写这样的导入?