包详细信息

reactify

andreypopp29.8kMIT1.1.1

Browserify transform for JSX (a superset of JS used by React.js)

react, browserify, browserify-transform, jsx

自述文件

reactify

Browserify transform for JSX (superset of JavaScript used in React library):

var React = require('react')

class Hello extends React.Component {

  render() {
    return <div>Hello, {this.props.name}!</div>
  }
}

Save the snippet above as main.js and then produce a bundle with the following command:

% browserify -t reactify main.js

reactify transform activates for files with either .js or .jsx extensions.

If you want to reactify modules with other extensions, pass an -x / --extension option:

% browserify -t coffeeify -t [ reactify --extension coffee ] main.coffee

If you don't want to specify extension, just pass --everything option:

% browserify -t coffeeify -t [ reactify --everything ] main.coffee

ES6 transformation

reactify transform also can compile a limited set of es6 syntax constructs into es5. Supported features are arrow functions, rest params, templates, object short notation and classes. You can activate this via --es6 or --harmony boolean option:

% browserify -t [ reactify --es6 ] main.js

es6 class getter and setter methods can be activated via --target es5 option:

% browserify -t [ reactify --es6 --target es5 ] main.js

You can also configure it in package.json

{
    "name": "my-package",
    "browserify": {
        "transform": [
            ["reactify", {"es6": true}]
        ]
    }
}

Troubleshooting

Code in 3rd-party packages isn't being transformed by reactify

By default Browserify applies transforms only for modules in the current package. That means that if there are modules with JSX in packages in node_modules/ directory then browserify will throw SyntaxError left and right even if you are using reactify.

The best way to fix that is ask package author to publish to npm with code compiled down to plain ES5 which is runnable in browsers and Node.js as-is.

Another approach is to ask to add

"browserify": {
  "transform": ["reactify"]
}

to the package's package.json. That will make Browserify apply reactify transform for that package too.

Another way is to activate reactify with -g option which will instruct Browserify to apply reactify to every module it encounters:

% browserify -g reactify main.js

Note that this will lead to slower builds as every module will be parsed and transformed by reactify even if it doesn't have JSX code in it.

更新日志

CHANGELOG

1.1.1

  • Correctly handle streams with multibyte characters inside (#67 by @uggedal)

1.1.0

  • Bump react-tools to 0.13.0.

1.0.0

  • Add source maps support.
  • Remove deprecated visitors option.
  • Remove previously exposed process function (wasn't documented).

0.17.0

  • Add --strip-types option (command line) or stripTypes option (JS API) to strip type declarations from source code.

  • Deprecate visitors option. Custom visitors should be executed in a separate browserify transform rather than in reactify.

0.16.0

  • Add target parameter to specify target runtime. The only allowed value is es5 at the moment.

0.15.1

  • Fix react-tools dependency

0.15.0

  • transform now works without the @jsx pragma

0.14.0

  • bump dependencies versions

  • remove deprecated features

0.13.1

  • bump dependencies jstransform dependency

0.13.0

  • include file path in error message.

0.11.0

  • add support for --visitors to allow additional jstransform visitors to be used for transformation.

0.10.0

  • add support for --es6/--harmony option to compile a limited set of es6 into es5. Supported features are arrow functions, rest params, templates, object short notation and classes.

  • add support for --everything to apply transform to every module

0.9.1

  • fix mathcing filename for extension

0.9.0

  • bump jstransform to 0.9.0

0.8.0

  • bump react-tools version to 0.9.0

  • deprecate reactify/undoubted transform

  • -x/--extension command line option to process files with specified extension

0.7.0

  • bump jstransform version

0.6.1

  • fix transform function override

0.6.0

  • allow transform function to be passed as an argument

  • export isJSXExtension regexp

0.5.1

  • add "browserify-transform" keyword to package metadata

0.5.0

  • move react-tools from peer deps to deps, update to 0.8.0

0.4.0

  • update to react-tools 0.5.0
  • mention filename if transform error occurred
  • fix bug with callstack explosion

0.3.1

  • rewrite in javascript

0.3.0

  • reactify/no-doubt transform which doesn't not require pragma even for .js files

0.2.2

  • check for the presence of @jsx pragma

0.2.1

  • update to react-tools 0.4.1

0.2.0

  • update to react-tools 0.4.0

0.1.4

  • fix test for @jsx pragma

0.1.3

  • preserve line numbers during transform

0.1.2

  • emit error event on error

0.1.1

  • update to react-tools 0.3.1
  • specs

0.1.0

  • initial release