Is there a way of piling multiple reactjs .jsx
files into one .js
file in one step?
something like:
jsxtool pile ./src/*.jsx --out app.js
Thanks.
Is there a way of piling multiple reactjs .jsx
files into one .js
file in one step?
something like:
jsxtool pile ./src/*.jsx --out app.js
Thanks.
Share Improve this question edited Jun 29, 2015 at 7:20 tokyovariable 1,65615 silver badges23 bronze badges asked Oct 31, 2014 at 13:47 joshuajoshua 4,1983 gold badges43 silver badges55 bronze badges2 Answers
Reset to default 8An easy way is to use gulp. Run npm install gulp
along with gulp-react
and gulp-concat
and make your gulpfile.js look like this:
var gulp = require('gulp');
var react = require('gulp-react');
var concat = require('gulp-concat');
gulp.task('default', function () {
return gulp.src('ponents/**')
.pipe(concat('singlefile.js'))
.pipe(react())
.pipe(gulp.dest('dist'));
});
Now run gulp
and boom, a single file!
This is the direct answer, which you can put in a shell script (say jsx-all.sh
).
find $1 -iname '*.jsx' | xargs cat | jsx
And usage:
jsx-all.sh src/ > app.js
The better answer is to use monjs modules. See browserify with reactify or webpack with jsx-loader. This is what most people in the react unity use.