grunt-contrib-requirejs compile gives an error while r.js works manually

844 views Asked by At

I am having problems with running requirejs as a grunt task to compile my js-files. When I run it manually (r.js.cmd -o configfile.js) with the same config file everything seems to work.

It seems that the grunt task is ingoring path definitions and is not capable to find my lib files.

>> Error: ENOENT, no such file or directory
>> '/path/to/project/js/lib.js'
>> In module tree:
>>     module
>>       libs/another-lib

The path should be /path/to/project/js/lib/lib.js. My main js-file (the one in data-main-attribute) has a requirejs.config call with correct path mapping ('lib': 'lib/lib.js'). After that I use them as parameters in a require call which starts the application.

My requirejs task configuration:

requirejs: {
    compile: {
        options: {
            name: "bootstrap",
            baseUrl: "submodule/js",
            mainConfigFile: "submodule/build.js",
            out: "submodule/js/bootstrap-built.js"
        }
    }
}

The only difference between grunt requrejs call and r.js.cmd -o build.js should be the grunt task configuration. They are using the same configuration file after all. What am I doing wrong or is there some kind of issue with paths in grunt-contrib-requirejs?

1

There are 1 answers

2
anssias On BEST ANSWER

My problem was a conflict between requirejs task options and the mainConfigFile. I wanted to use the same config file from the submodule in the main project but there is a different base url configured (submodule/js/ -> js/).

I haven't found a way to override options from the config file so I had to copy them to the task configuration. It isn't pretty but at least it works now.