【问题标题】:Possible to skip inlined, named modules with r.js build?可以使用 r.js 构建跳过内联的命名模块吗?
【发布时间】:2014-01-08 21:38:08
【问题描述】:

在我的应用程序中,我在 index.html 中内联定义了一个命名模块:

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

我需要在我的网页中定义它,因为我在使用环境变量时会用到一些东西。所以,在我的模块中,我可以包含“config”:

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

当我使用 Grunt(grunt-require,它使用 r.js)运行 RequireJS 构建时,它抱怨它没有找到 config.js。我的构建配置如下所示:

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

当我构建时,我得到:

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

如何允许将命名的内联定义模块与 r.js 构建结合使用?

【问题讨论】:

    标签: javascript build requirejs r.js


    【解决方案1】:

    设置

    paths: {
       config : 'empty:'
    }
    

    在您的构建配置文件中应将此模块排除在优化过程之外,因此,停止引发此错误。

    但是这种方式有点棘手,因为这个选项通常用于排除第三方依赖(例如,在开发一些基于Backbone的js库时,最好将你的lib与Backbone分开)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      • 2017-07-09
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多