简体   繁体   中英

Possible to skip inlined, named modules with r.js build?

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM