I need to convert all /src/.jsx files to /src/.js
Before I used gulp-react:
var react = require('gulp-react');
gulp.task('jsx', function () {
return gulp.src('src/jsx/*.jsx')
.pipe(react())
.pipe(gulp.dest('src/js/'));
});
It works but not without some small mistakes. When I use Babel website (https://babeljs.io/repl/) all converts right. Could you help me. How can I set gulp to convert .JSX files?
In order to get displayName automatically inserted on transformation, you need to install gulp-babel and React preset:
and then in the gulpfile.js:
First you need to install these two packages:
then you can convert like this:
since I am also using ES6.
Yeah using gulp with the package gulp-babel would do the trick.
https://github.com/babel/gulp-babel
For latest React v16.8.x using Babel 7, use
@babel/preset-env
and@babel/preset-react
modules.Then in your gulpfile.js: