I am trying to execute the workflow suggested in this file: https://gist.github.com/nateajohnson/4d16df279d2e3d2b6b16 , so that in the end I get two separate .js files: one for the vendor vendors and the other for my own code.
My Gulpfile.js:
var gulp = require('gulp'), // ... there shouldn't be any problems gulp.task('build-vendor', function() { var b = browserify({ debug: false}); b.require(nodeResolve.sync('jquery'), { expose: 'jquery' }); b.require(nodeResolve.sync('react'), { expose: 'react' }); b.require(nodeResolve.sync('react/addons'), { expose: 'react/addons' }); b.require(nodeResolve.sync('react-select'), { expose: 'react-select' }); var stream = b.bundle() .pipe(source('vendor.js')) .pipe(gulp.dest('assets/build/js')) .pipe(buffer()) .pipe(uglify()) .pipe(rename('vendor.min.js')) .pipe(gulp.dest('assets/build/js')) .pipe(gzip()) .pipe(gulp.dest('assets/build/js')); return stream; }) ; gulp.task('build-app', function() { var b = browserify('assets/dev/js/app.js', { debug: false }); b.external('jquery'); b.external('react'); b.external('react-select'); var stream = b.transform(babelify, { stage: 0 }) .bundle() .on('error', function(e){ console.log(e.message); this.emit('end'); }) .pipe(source('bundle.js')) .pipe(gulp.dest('assets/build/js')); return stream; });
When I try to use the React variable in my own code, I get an error:
Untrained ReferenceError: React not defined
I can get rid of this by turning
var React = require('react');
in each of my js files that use reaction, or by including
<script src="https://fb.me/react-0.13.3.min.js"></script>
in my HTML (which is clearly not a very good solution).
Just in case, I clicked this project on github: https://github.com/jehaby/ireact/tree/master/kindle
So my questions are why I get this error and how to solve it correctly (I'm sure there are some)? I think these might be silly questions, but I'm new to these tools. I have already spent several hours trying to understand what is wrong, and now I feel that I'm stuck. We will be very grateful for any help.