ワークフローを作成しようとしています。TypeScriptを使用してReactモジュールを作成し、Gulp.js経由でJavaScriptに自動コンパイルすることができます。私はTypeScript 1.6.2、gulp-reactとgulp-typescriptを使用しています。TypeScript、React、Gulp.js - reactを定義する
マイ.tsx
ファイル次のようになります。
/// <reference path="../../../../typings/react/react.d.ts" />
import React = __React;
interface HelloWorldProps {
name: string;
}
var HelloMessage = React.createClass<HelloWorldProps, any>({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
React.render(<HelloMessage name="helloooo" />, document.getElementById('test'));
私の問題は、この行です:import React = __React;
私はそれを除外すると、私はエラー
エラーTS2304を取得:することはできません「React」という名前を見つけてください。
.tsx
を.js
にコンパイルすると(しかし、まだJSXにコンパイルされ、出力を使用できます)。私はそれを置くと、私はエラーなしでコンパイルすることができますが、私はブラウザ内でファイルを使用しようとすると、私はもちろんUncaught ReferenceError: __React is not defined
を取得します。
これは私のgulptaskがどのように見えるかです:
gulp.task('gui-tsx', function() {
var tsResult = gulp.src(config.guiSrcPath + 'tsx/app.tsx')
.pipe(ts({
jsx: 'react'
}));
return tsResult.js.pipe(gulp.dest(config.guiSrcPath + 'jsx'));
});
は、このための回避策はありますか?または私はここに何かを逃していますか?
は、任意の同様の解決策はありますか? – jpierson