简体   繁体   English

gulp browserify + reactify不创建包

[英]gulp browserify + reactify not creating bundle

When I run gulp I get an "updating!" 当我大口吃时,我会得到“更新中!” and "updated!" 和“已更新!” log after saving main.js but there's no bundle ever built 保存main.js之后记录日志,但没有构建捆绑包

gulpfile.js : 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. 我尝试过更改目录并重新加载所有内容,但没有任何效果。

Update lines that contain gulp.dest('/build/') to gulp.dest(__dirname + '/build/') . 将包含gulp.dest('/build/')行更新为gulp.dest(__dirname + '/build/') Currently your file located at drive_root_dir/build/main.js 当前,您的文件位于drive_root_dir / build / main.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM