Splitting React Components Into Separate Files
This seems to be a common question, I'm finding a lot of people asking it and the responses are all very different and seem to be a bit hit and miss. I've watched various video tut
Solution 1:
Your es6 example of exporting like export default Square
should work fine. It looks like you've installed babelify but you're not using it in the transform process, hence why the browser is complaining that you're trying to use es6 features outside of strict mode.
If you look at the babelify instructions it says to do something like:
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var gutil = require('gulp-util');
gulp.task('browserify', function () {
browserify('./src/main.js', { debug: true })
.transform('babelify', {presets: ['es2015', 'react']})
.bundle()
.on('error', gutil.log)
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist'))
});
gulp.task('watch',function() {
gulp.watch('./src/**/*.js', ['browserify'])
});
It looks like you only have babel-preset-react
installed, you'll need to do npm i babel-preset-es2015 --save-dev
. Also babelify
and babel-preset-react
are fine as devDependencies
.
Post a Comment for "Splitting React Components Into Separate Files"