Answer the question
In order to leave comments, you need to log in
How to add gulp-react to compile jsx files on the fly?
Hello!
For the project I use one of the yoeman generators, namely generator-gulp-angular. Very satisfied, the generator does a lot of useful work on combining, minifying scripts, styles, etc.
It even glues and includes Angular templates.
Faced with the task of attaching ReactJs to the project. I would like to combine all jsx templates into one file, then compile to js and paste it into the project
. I tried to add the following task to gulp
var gulp = require('gulp');
var react = require('gulp-react');
var concat = require('gulp-concat');
var paths = gulp.paths;
gulp.task('jsxconcat', function () {
return gulp.src(paths.src + '/{app,components}/**/*.jsx')
.pipe(concat(paths.src + '/app/singlefile.js'))
.pipe(react())
.pipe(gulp.dest(paths.tmp +'/serve'));
});
Answer the question
In order to leave comments, you need to log in
Probably due to asynchrony.
This is how I cured less + css - with the run-sequence module .
As I see it, you will be like
var runSequence = require('run-sequence');
// .. some code
gulp.task('watch', [ /* deps list */ ], function(cb) {
runSequence('jsxconcat', 'includeFilesToIndex.html', cb);
});
I figured it out, it's still useful to talk to smart people
. The error was that in task 'jsxconcat' I saved the resulting file to the directory with the already "compiled" code.
Now I changed it so that the file is saved to the directory with the source code and everything began to work! jsxconcat compiles jsx puts the already compiled javascript file in a directory with other scripts and then the inject task includes all the scripts in the main project file
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question