我找到的所有文档都解释了如何在React中使用TypeScript,但是我对与snabbdom-jsx一起使用它很感兴趣?知道如何配置tsconfig才能工作吗?
关于使用babel的snabbdom-jsx文档:
顶部的/** @jsx */实用化告诉Babel使用html函数而不是React.createElement默认值。html函数接受Babel传递的参数,并按照Snabbdom的补丁函数的要求生成虚拟节点。
是否有类似于@jsx html
配置的TypeScript?
发布于 2016-05-07 02:11:24
顶部的/** @jsx */ use告诉Babel使用html函数而不是React.createElement 是否有类似于TypeScript的@jsx配置的东西?
是。它的reactNamespace
。例如,reactNamespace foo
,然后你得到foo.createElement
。您可以使用它来创建foo.createElement = someOhterLibMethod
,使其与任何东西一起工作。
更多
https://basarat.gitbooks.io/typescript/content/docs/jsx/tsx.html
在alm中也支持
发布于 2016-10-26 01:25:02
这是我工作的gulp文件,它将.tsx转换为snabbdom虚拟域。
跳过/** @jsx */ TypeScript,导入不工作于TypeScript 2的{ html }。
gulp.task('default', function () {
return browserify({
basedir: '.',
debug: true,
entries: [paths.tsadmin],
cache: {},
packageCache: {},
plugin: [tsify]
})
.transform('babelify', {
extensions: [".tsx", ".ts", ".js", ".jsx"]
})
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.webroot + '/js'));
});
和.babelrc文件。
{
"presets": [
"es2015"
],
"plugins": [
"syntax-jsx",
[
"transform-react-jsx",
{
"pragma": "bsj.html"
}
],
[
"jsx-pragmatic",
{
"module": "snabbdom-jsx",
"import": "bsj"
}
]
]
}
https://stackoverflow.com/questions/37085276
复制