我刚刚开始了解parceljs,发现它非常令人愉快,只有一件事看起来有点夸张:
我正在使用parceljs将infernojs的tsx文件转换为javascript。但是,生成的代码包含原始的React.createElement函数,该函数显然不能工作:
inferno_1.render(React.createElement("div", null, "woot"), document.getElementById("app"));
我见过使用带有插件babel- plugin -inferno的.babelrc文件的例子,这似乎是有效的,但由于它添加了各种babel依赖项,我只是想知道是否有一种方法可以指定转换函数,而不是所有额外的负担。(因为parcel似乎是关于简单和所有的)
发布于 2020-04-06 21:33:51
类似的,你只需要在你的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://stackoverflow.com/questions/57101022
复制相似问题