0

reacts jsx テンプレート/コンポーネントを使用して静的サイト ジェネレーターを作成したいと思っています。これを可能にするために、ジキルとミドルマンをハッキングする必要がありました...

しかし、プラグインでhttp://www.metalsmith.ioを発見しました: https://github.com/yeojz/metalsmith-react-templates

私はこれまでにフォローしています:

var Metalsmith    = require('metalsmith');
var reactTemplate = require('metalsmith-react-templates');

Metalsmith(__dirname)
  .clean(true)
  .use(reactTemplate({
    directory: 'templates',
    isStatic: true
  }))
  .source('src')
  .destination('build')
  .build(function(err) {
    if (err) throw err;
  });

および jsx ファイル:

var React = require('react');

var Entry = React.createClass({
  render: function() {

    return ();
  }
});

module.exports = Entry;

node build.js を実行すると、エラーが発生します。

entry.jsx: Unexpected token

ここに画像の説明を入力

metalsmith-react-templates の例は時代遅れのようで、問題はありますか?

提案@を試しました:

  4 |   render: function() {
  5 | 
> 6 |     return (<p>Entry</p>);
    |             ^
  7 |   }
  8 | });
  9 | 
4

1 に答える 1

2

@サリバン

を実行しても問題が解決しない場合はreturn (<p>Entry</p>);、実際にはbabelコンパイラの問題である可能性が高くなります。

のどのバージョンbabelを使用していますか?

バージョン 6 以上の場合は、少なくともbabel-preset-reactbabel-preset-es2015プラグインがインストールされていることを確認してください。

于 2016-02-22T15:06:30.473 に答える