【问题标题】:gulp browserify + reactify not creating bundlegulp browserify + reactify 不创建包
【发布时间】:2023-03-16 10:35:01
【问题描述】:

当我运行 gulp 时,我得到一个“更新!”和“更新!”保存 main.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']);

我的文件结构是

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

我没有发现任何错误,此时我完全迷失了。我尝试更改目录并重新加载所有内容,但没有任何效果。

【问题讨论】:

    标签: reactjs gulp reactify


    【解决方案1】:

    将包含gulp.dest('/build/') 的行更新为gulp.dest(__dirname + '/build/')。目前您的文件位于 drive_root_dir/build/main.js

    【讨论】:

    • 嗯...我认为这会起作用,但我仍然没有看到任何正在创建的东西
    • 你的版本似乎可以工作,但现在我收到一个关于加载两个版本的反应的不变错误......可能是我的结果
    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 2015-04-20
    • 2015-08-05
    • 2015-10-02
    • 2015-04-27
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    相关资源
    最近更新 更多