我如何将 tsx 与 snabbdom-jsx(不是 React)一起使用?
How can I use tsx with snabbdom-jsx (not React)?
我找到的所有文档都解释了如何将 TypeScript 与 React 一起使用,但我有兴趣将它与 snabbdom-jsx 一起使用吗?关于如何配置 tsconfig 以使其工作的任何想法?
来自 snabbdom-jsx 关于使用 babel 的文档:
The /** @jsx html */ pragma at the top tells Babel to use the html function instead of the React.createElement default. The html function takes arguments passed from Babel and generates virtual nodes as expected by Snabbdom's patch function.
是否有与此 @jsx html
TypeScript 配置等效的东西?
The /** @jsx html */ pragma at the top tells Babel to use the html function instead of the React.createElement
Is there something equivalent to this @jsx html configuration for TypeScript ?
是的。它的 reactNamespace
。例如。 reactNamespace foo
然后你得到 foo.createElement
。您可以使用它来创建 foo.createElement = someOhterLibMethod
以使其与任何东西一起工作。
更多
https://basarat.gitbooks.io/typescript/content/docs/jsx/tsx.html
也支持
这是我的工作 gulp 文件,它将 .tsx 转换为 snabbdom 虚拟 dom。
跳过 /** @jsx html */ pragma 并导入不在 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"
}
]
]
}
我找到的所有文档都解释了如何将 TypeScript 与 React 一起使用,但我有兴趣将它与 snabbdom-jsx 一起使用吗?关于如何配置 tsconfig 以使其工作的任何想法?
来自 snabbdom-jsx 关于使用 babel 的文档:
The /** @jsx html */ pragma at the top tells Babel to use the html function instead of the React.createElement default. The html function takes arguments passed from Babel and generates virtual nodes as expected by Snabbdom's patch function.
是否有与此 @jsx html
TypeScript 配置等效的东西?
The /** @jsx html */ pragma at the top tells Babel to use the html function instead of the React.createElement
Is there something equivalent to this @jsx html configuration for TypeScript ?
是的。它的 reactNamespace
。例如。 reactNamespace foo
然后你得到 foo.createElement
。您可以使用它来创建 foo.createElement = someOhterLibMethod
以使其与任何东西一起工作。
更多
https://basarat.gitbooks.io/typescript/content/docs/jsx/tsx.html
也支持这是我的工作 gulp 文件,它将 .tsx 转换为 snabbdom 虚拟 dom。
跳过 /** @jsx html */ pragma 并导入不在 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"
}
]
]
}