3
3

More than 5 years have passed since last update.

react-jadeのテンプレートをプレコンパイルしてから使う

Last updated at Posted at 2014-11-29

mizchi/react-jade-precompiler

jadejs/react-jadeを使うとわかるのだけど、react-jadeのtemplateのパース処理は実は結構重い。最終的にはJSの関数になるので、その関数だけダンプしとけばいいやみたいな雑な感じで作った。Function.prototype.toString()に依存しているので、壊れるケースは多分ありそうな気がする。自分の手持ちのテンプレートだと問題はなかった。

使い方

template.jadeを持っているとする

$ npm install -g mizchi/react-jade-precompiler 
$ react-jade-precompiler template.jade -o template.js # generate file

Reactのrenderに食わせてやれば動く。

var tmpl = require('./template');
var React = require('react');

React.createClass(
  render: function(){
    return tmpl({foo: 1, bar: ["param"]}); //=> Generate virtual DOM 
  }
);

でもこの機能は本体に持ってほしいよなぁという気持ちもあり、実際壊れるケースあるの?みたいな質疑こめて、GithubにIssueを建立して今回は終了。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3