Access RequireJS path configuration

前端 未结 2 2003
予麋鹿
予麋鹿 2021-02-15 15:10

I notice in the documentation there is a way to pass custom configuration into a module:

requirejs.config({
    baseUrl: \'./js\',
    paths: {
        jquery: \         


        
2条回答
  •  庸人自扰
    2021-02-15 15:59

    I don't believe require exposes that anywhere, at least I can't find it looking through the immense codebase. There are two ways you could achieve this though. The first and most obvious is to define the config as a global variable. The second, and closer to what you want, is to create a require plugin that overrides the load function to attach the config to the module:

    define({
        load: function (name, req, onload, config) {
            req([name], function (value) {
                value.requireConfig = config;
                onload(value);
            });
        }
    });
    

提交回复
热议问题