包详细信息

mercury-jsxify

Raynos12MIT0.14.0

browserify v2 plugin for mercury-jsx to support jsx

mercury, browserify, browserify-transform, v2

自述文件

mercury-jsxify

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

/**
 * @jsx h
 */

var h = require("mercury").h

function hello(name) {
  return <div>Hello, {name}!</div>
}

mercury.app(
  document.getElementById('hello'),
  mercury.value('world'),
  hello
)

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

% browserify -t mercury-jsxify main.js

mercury-jsxify transform activates for files with either .jsx extension or /** @jsx React.DOM */ pragma as a first line for any .js file.

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

% browserify -t coffeeify -t [ mercury-jsxify --extension coffee ] main.coffee

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

% browserify -t coffeeify -t [ mercury-jsxify --everything ] main.coffee

ES6 transformation

mercury-jsxify 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 [ mercury-jsxify --es6 ] main.js

You can also configure it in package.json

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

Using 3rd-party jstransform visitors

mercury-jsxify uses jstransform to transform JavaScript code. It allows code transformations to be pluggable and, what's more important, composable. For example JSX and es6 are implemented as separate code transformations and still can be composed together.

mercury-jsxify provides --visitors option to specify additional jstransform visitos which could perform additional transformations.

It should point to a module which exports visitorList attribute with a list of transformation functions to be applied:

% browserify -t [ mercury-jsxify --visitors es6-module-jstransform/visitors ] main.js

Example above uses es6-module-jstransform to compile es6 module syntax (import and export declarations) into CommonJS module constructs.

更新日志

CHANGELOG

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