我刚刚了解 parceljs 并发现它非常令人愉快,只有一件事似乎有点矫枉过正:
我正在使用 parceljs 将 infernojs 的 tsx 文件转换为 javascript。但是,生成的代码包含原始的React.createElement函数,该函数显然无法正常工作:
inferno_1.render(React.createElement("div", null, "woot"), document.getElementById("app"));
我见过使用带有插件 babel-plugin-inferno 的 .babelrc 文件的示例,这似乎有效,但由于这增加了各种 babel 依赖项,我只是想知道有没有办法指定转换函数,没有所有额外的包袱。(因为包裹似乎是关于简单和所有(
类似地,你只需要在你的tsconfig中设置"jsxFactory":"h",然后从你计划使用它的"inferno-hyperscript"导入它。
TSCONFIG:
{
"compilerOptions": {
"target": "es5",
"jsx":"react",
"jsxFactory":"h",
"lib":["dom","ESNext"],
"module": "commonjs",
"strict": true,
"moduleResolution":"Node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include":["src"]
}
在代码中使用:
import { h } from 'inferno-hyperscript';
function App() {
return (
<div className="App">
Hello thar
</div>
);
}
export default App;
您可能会以类似的方式使用 inferno-create-element,但我只尝试过 htags。
举个例子:https://github.com/jayy-lmao/inferno-parcel-ts