This is a very simple Gradle plugin to transform JSX sources into JavaScript. It was inspired by and is using the gradle-node-plugin from Sten Roger Sandvik.
React is
A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES
developed at Facebook and Instagram.
Releases of this plugin are hosted at BinTray (http://bintray.com) and is part of jcenter repository. Setup the plugin like this:
plugins {
id 'net.eikehirsch.react' version '0.4.1'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.eikehirsch.react:gradle-react-plugin:0.4.1'
}
}
apply plugin: 'net.eikehirsch.react'
The plugin will also apply gradle-node-plugin for Node and NPM related tasks. (see http://github/srs/gradle-node-plugin for details).
Simply run
./gradlew jsx
to transform any js file in src/main/react
. The resulting files will be stored at build/react
.
To change the defaults you can put all your settings into the jsx
namespace:
jsx {
sourcesDir = 'src/react'
destDir = 'out'
// optional
options {
extension = 'jsx' // js is the default extension
}
}
You can define the input and output folders without using the extension namespace like this:
task myJSX( type: JSXTask ) {
sourcesDir = 'src/react'
destDir = 'out'
// optional
options {
extension = 'js' // js is the default extension
}
}
(You can try this at the configuration example project)
If you want to have your jsx sources transformed everytime you build your project, you could do something like this:
processResources.dependsOn jsx
// for older gradle versions (e.g. 1.4) use:
processResources.dependsOn 'jsx'
To build the plugin, just type the following command:
./gradlew clean build
- Thanks to Sten R. Sandvik for his node plugin
- that's all for now.