amd-optimize icon indicating copy to clipboard operation
amd-optimize copied to clipboard

Example of configFile import

Open beenanner opened this issue 10 years ago • 3 comments

I'm not sure what I'm doing wrong as the documentation doesn't actually show a good example of using a config file. When running the following

gulp.task('amdoptimize', function() {
    amdOptimize.src("main.default", {
        configFile : "./configs/amd.json",
        baseUrl : "./js",
        dir:"./js/build"
    })
    .pipe(concat("main.default.js"))
    .pipe(gulp.dest("js/build"));
});

I get the following error. :'(

[16:58:23] Finished 'amdoptimize' after 11 ms
Error: No file for module 'jquery' found.
...

Here is my amd.json file.

({
    "paths": {
        "jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
    },
    "map": {
        "*": {
            "facebook": "//connect.facebook.net/en_US/all.js",
            "facebook-debug": "//connect.facebook.net/en_US/all/debug.js"
        }
    },
    "config": {
        "version": {
            "libs/jquery/lazyload": "1.9.3",
            "libs/jquery/mobile": "1.4.0a1",
            "libs/jquery/numberformatter": "1.2.3",
            "libs/jquery/placeholder": "0.2.4",
            "libs/jquery/scrollbar": "0.2.4.custom",
            "libs/jquery/tablesorter": "2.0.5",
            "libs/jquery/wysibb": "1.5.1",
            "libs/jquery/ui/jquery.ui.core": "1.9.2",
            "libs/jquery/ui/jquery.ui.draggable": "1.9.2",
            "libs/jquery/ui/jquery.ui.mouse": "1.9.2",
            "libs/jquery/ui/jquery.ui.position": "1.9.2",
            "libs/jquery/ui/jquery.ui.slider": "1.9.2",
            "libs/jquery/ui/jquery.ui.touch-punch": "0.2.2"
        }
    }
})

Any idea what I'm doing wrong?

beenanner avatar Jul 16 '15 21:07 beenanner

There is no support for remote scripts yet. That's why it can't find jquery at runtime.

normanrz avatar Jul 17 '15 07:07 normanrz

Thanks for the quick reply @normanrz so if I wanted to load a path relatively it seems the inline configs vs an external configFile are different? It seems to work if I inline the configs but I don't think that would be very DRY if I wanted to create a task for each page in my app. :-)

Loading inline this works.

"paths": {
        "jquery": "../../js/libs/jquery-1.8.3",
    },

If I drop that in a config file I get the previous error mentioned.

Error: No file for module 'jquery' found.

Seems the module.exports.loader is getting the wrong path when using the config file. It's as if it ignores the paths setup and just looks in the basePath. I'm still trying to track down the original code that sets that and I could possible submit a patch if you don't figure it out first. :-p

beenanner avatar Jul 17 '15 15:07 beenanner

I was able to work around the configFile issue for now by moving the paths to be inline with the gulp task before loading the configFile.

Current setup gulpfile.js

gulp.task('amdoptimize', function() {
    amdOptimize.src("main.default", {
        "paths": {
              "jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
        },
        configFile : "./configs/amd.json",
        baseUrl : "./js",
        dir:"./js/build"
    })
    .pipe(concat("main.default.js"))
    .pipe(gulp.dest("js/build"));
});

amd.json file

({
    "map": {
        "*": {
            "facebook": "//connect.facebook.net/en_US/all.js",
            "facebook-debug": "//connect.facebook.net/en_US/all/debug.js"
        }
    },
    "config": {
        "version": {
            "libs/jquery/lazyload": "1.9.3",
            "libs/jquery/mobile": "1.4.0a1",
            "libs/jquery/numberformatter": "1.2.3",
            "libs/jquery/placeholder": "0.2.4",
            "libs/jquery/scrollbar": "0.2.4.custom",
            "libs/jquery/tablesorter": "2.0.5",
            "libs/jquery/wysibb": "1.5.1",
            "libs/jquery/ui/jquery.ui.core": "1.9.2",
            "libs/jquery/ui/jquery.ui.draggable": "1.9.2",
            "libs/jquery/ui/jquery.ui.mouse": "1.9.2",
            "libs/jquery/ui/jquery.ui.position": "1.9.2",
            "libs/jquery/ui/jquery.ui.slider": "1.9.2",
            "libs/jquery/ui/jquery.ui.touch-punch": "0.2.2"
        }
    }
})

beenanner avatar Jul 17 '15 15:07 beenanner