Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  98] [ 4]  / answers: 1 / hits: 42238  / 10 Years ago, sun, january 11, 2015, 12:00:00

I would like to understand the technical difference between them so as to determine the appropriate one to use.


I've realised that they can both have same content and sometimes used interchangeably in some projects.


How does .jsx files differ from .js?


More From » reactjs

 Answers
33

Update for Newer Users



The JSX Compiler tool has been removed as JSXTransformer has been deprecated. The React Team recommends using another tool such as the Babel REPL.






If you wish to keep the JSX source code intact for better maintainability, I would keep them as .jsx files. Using the JSX Compiler, either manually or via build script, will convert your JSX syntax to normal JavaScript files.



Note: It is possible to serve JSX files in your production environment but React will give you console notices about reduced performance.






Personally, I would use something like gulp-jsx or gulp-reactify to convert the files.



Example with gulp-jsx:





var gulp = require('gulp');
var jsx = require('gulp-jsx');

gulp.task('build', function() {
return gulp.src('path/to/*.jsx')
.pipe(jsx())
.pipe(gulp.dest('dist'));
});

[#68246] Thursday, January 8, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billt

Total Points: 608
Total Questions: 100
Total Answers: 87

Location: Cape Verde
Member since Fri, Nov 27, 2020
4 Years ago
;