Question

In my application, I have a named module defined inline in index.html:

<script>
    define('config', {
        mode: '...',
        environment: '...',
        apiUrl: '...',
        rootPath: '...',
        baseImageUrl: '...'
    });
</script>

I need to define this in my web page because I pull some stuff in using environment variables. So, in my modules, I can then include 'config':

define(['config', 'jquery'], function(config, $) { ... });

When I run a RequireJS build using Grunt (with grunt-require, which uses r.js), it's complaining that it's not finding config.js. My build configuration looks like this:

{
    baseUrl: 'js',
    main: 'app/Main',
    dir: 'js/build',
    out: null,
    modules: { ... },
    paths: { ... },
    shim: { ... }
}

When I build, I get:

Error: Error: ENOENT, no such file or directory '/projects/projectname/js/build/config.js

How can I allow for use of named, inline-defined modules in conjunction with an r.js build?

Was it helpful?

Solution

Setting

paths: {
   config : 'empty:'
}

in your build configuration file should exclude this module out of optimization process and, as a result, stop raising this error.

But this is a bit tricky way, because this option is commonly used to exclude third-party dependencies (for example, when developing some js library based on Backbone, it would be better to separate your lib from Backbone)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top