我有一个main.js文件,其中包含一些代码和其中几个require('some_other_file.js');行(这又可能需要一些其他文件)。

要求:使用Gulp 4.0,我想通过将main.js文件作为源文件,将所有这些文件合并到一个文件中,然后让一些Gulp插件找出还需要包含哪些其他文件(所以不仅仅是简单地对所有文件使用合并!)。

在gulp中使用requirejs只需将require(...);行添加到输出文件中。

gulp.task('compile_js', function(cb) {

    var config = {
        baseUrl: './src/js/',
        include: ['main'],
        out: './dist/main.js',
    };

    rjs.optimize(config, function(buildResponse){
        console.log('build response', buildResponse);
        cb();
    }, cb);
});


我用requirejs做错了吗,还是有一个Gulp插件可以解决这个问题?

最佳答案

找到了! Browserify似乎可以解决问题。

Browserify:http://browserify.org/

还有Gulp中的实现:https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-uglify-sourcemap.md

10-05 20:51
查看更多