-
-
Save sjingo/e2c2450a5754307a85569960a7ee36c7 to your computer and use it in GitHub Desktop.
Basic react gulpfile with browserfy and babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var source = require('vinyl-source-stream'); | |
var buffer = require('vinyl-buffer'); | |
var watch = require('gulp-watch'); | |
var gutil = require('gulp-util'); | |
var browserify = require('browserify'); | |
var babel = require('gulp-babel'); | |
var env = ['development','production']; | |
gulp.task('set-env', function() { | |
return process.env.NODE_ENV = env[1]; | |
}); | |
gulp.task('transform', function() { | |
return gulp.src('./app/src/**/*.jsx') | |
.pipe(babel({ | |
presets: ["react", "es2015"] | |
})) | |
.pipe(gulp.dest('./app/dist')); | |
}) | |
gulp.task('js', ['transform'], function() { | |
// Assumes a file has been transformed from | |
// ./app/src/main.jsx to ./app/dist/main.js | |
return browserify('./app/dist/main.js') | |
.bundle() | |
.on('error', gutil.log) | |
.pipe(source('main.js')) | |
.pipe(buffer()) | |
.pipe(gulp.dest('./')) | |
}); | |
gulp.task('default', ['set-env','js'], function() { | |
gulp.watch('./app/**/*.jsx', ['js']); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Hello React!</title> | |
</head> | |
<body> | |
<div id="example"></div> | |
<script src="/main.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
npm install --save-dev babel-preset-es2015 browserify gulp gulp-babel gulp-notify gulp-util gulp-watch react react-dom vinyl-buffer vinyl-source-stream babel-preset-react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./app/src/main.jsx | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
ReactDOM.render( | |
<h1>Hello, world!</h1>, | |
document.getElementById('example') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment