jlouns / gulp-requirejs-optimize

Wrapper for the requirejs optimizer for use in gulp
MIT License
62 stars 9 forks source link

what does 'src' use for when optimize single module #25

Closed githoniel closed 7 years ago

githoniel commented 8 years ago

my build file is like

{
        name: "hermes",
        out: "./dist/hermes.js",
        baseUrl: "./",
        mainConfigFile: "main.js",
        preserveLicenseComments: !1,
        generateSourceMaps: !1,
        optimizeCss: "none",
        writeBuildTxt: !1
 }

as it's use to optimize a module and will generate one file

for(let moduleName in buildConfig){
     gulp.task("rjs:"+moduleName, function () {
        return gulp.src(
                [
                    './empty.js'
                ]
            )
            .pipe(requirejsOptimize(function(file){
                return buildConfig[moduleName]
            }))
            .pipe(gulp.dest("./"));
    });
    taskList.push('rjs:'+moduleName);
}

What does gulp.src use for ? And How can I remove it? If the file path is null/undefied or no file path , it's broken. If the path is the whole app , it will scan all file and optimizing all file and waste a lot of time. So I have to add a empty.js to make it run

jlouns commented 8 years ago

The file that is passed into gulp.src is used to set the include and out parameters of the build. However, if those parameters exist in your build config, it ignores them and uses whatever you supply. I don't know exactly how your project and r.js build options are set up, but assuming all of your modules are in the root of your source tree you could do something like this:

for (let moduleName in buildConfig) {
     gulp.task("rjs:"+moduleName, function() {
        return gulp.src([moduleName + '.js'])
            .pipe(requirejsOptimize({
                baseUrl: "./",
                mainConfigFile: "main.js",
                preserveLicenseComments: !1,
                generateSourceMaps: !1,
                optimizeCss: "none",
                writeBuildTxt: !1
            }))
            .pipe(gulp.dest("./dist"));
    });
    taskList.push('rjs:'+moduleName);
}