Using requirejs optimizer node module with Gulp

前端 未结 2 819
暖寄归人
暖寄归人 2021-02-06 13:45

There\'s gulp-requirejs plugin, but it\'s blacklisted with the following message: "use the require.js module directly".

The docs are quite sparse, how would I b

相关标签:
2条回答
  • 2021-02-06 13:59

    To do this without invoking the shell, you can do it like:

    var gulp = require('gulp'),
        rjs = require('requirejs'),
    
        config = {
            baseUrl: '../appDir/scripts',
            name: 'main',
            out: '../build/main-built.js'
        };
    
    gulp.task('scripts', function(cb){
        rjs.optimize(config, function(buildResponse){
            // console.log('build response', buildResponse);
            cb();
        }, cb);
    });
    

    see: https://github.com/phated/requirejs-example-gulpfile/blob/master/gulpfile.js

    0 讨论(0)
  • 2021-02-06 14:20

    I just ended up running the r.js build command with gulp-shell:

    var gulp = require('gulp'),
        shell = require('gulp-shell');
    
    // Run the r.js command, so simple taks :)
    gulp.task('scripts', shell.task([
        'r.js -o build/r/build.js'
    ]))
    

    It takes roughly 2 seconds to run, not too long at all.

    The r settings are defined in an external build.js file that Gulp knows nothing about.

    0 讨论(0)
提交回复
热议问题