1

When I run gulp I get an "updating!" and "updated!" log after saving main.js but there's no bundle ever built

gulpfile.js:

var watchify = require('watchify');
var reactify = require('reactify'); 
var concat = require('gulp-concat');
var util = require('gulp-util');

gulp.task('browserify', function() {
    var bundler = browserify({
        entries: ['./dist/main.js'], // Only need initial file, browserify finds the deps
        transform: [reactify], // We want to convert JSX to normal javascript
        debug: true, // Gives us sourcemapping
        cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
    });
    var watcher  = watchify(bundler);

    return watcher
    .on('update', function () { // When any files update
        var updateStart = Date.now();
        console.log('Updating!');
        watcher.bundle() // Create new bundle that uses the cache for high performance
        .pipe(source('main.js'))
        .on('error', util.log)
    // This is where you add uglifying etc.
        .pipe(gulp.dest('/build/'));
        console.log('Updated!', (Date.now() - updateStart) + 'ms');
    })
    .on('error', util.log)
    .bundle() // Create the initial bundle when starting the task
    .pipe(source('main.js'))
    .pipe(gulp.dest('/build/'))
    .on('error', util.log);
});

// I added this so that you see how to run two watch tasks
gulp.task('css', function () {
    gulp.watch('styles/**/*.css', function () {
        return gulp.src('styles/**/*.css')
        .pipe(concat('main.css'))
        .pipe(gulp.dest('build/'));
    });
});

// Just running the two tasks
gulp.task('default', ['browserify', 'css']);

My file structure is

/build  
/dist   
 -index.html  
 -main.js 
/node_modules  
/styles 
gulpfile.js

I am not finding any errors and I am completely lost at this point. I've tried changing directories around and reloading everything but nothing works.

1 Answer 1

1

Update lines that contain gulp.dest('/build/') to gulp.dest(__dirname + '/build/'). Currently your file located at drive_root_dir/build/main.js

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm...I thought this would work but I still am not seeing anything being created
your version seems to work except now I'm getting an invariant error about loading two versions of react...probably something on my end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.