【问题标题】:RequireJS / r.js 'baseURL' Property Seemingly IgnoredRequireJS / r.js 'baseURL' 属性似乎被忽略了
【发布时间】:2012-08-09 05:15:59
【问题描述】:

我正在尝试使用 r.js 优化器将我的所有依赖项构建到一个文件中。这是我的文件结构:

app
  bin
  src
    css
      main.css
    js
      libs
        raphael-2.1.0
          eve.js
          raphael.amd.js
          raphael.core.js
          raphael.svg.js
          raphael.vml.js
        jquery-1.8.0.js
        require-2.0.5.js
      main.js
    build.js
    index.html
  r.js

这里是 build.js 的内容:

({
  baseURL: 'js',
  dir: '../bin',
  paths: {
    'jquery': 'libs/jquery-1.8.0',
    'raphael': 'libs/raphael-2.1.0/raphael.amd'
  },
  name: 'main',
  removeCombined: true
})

'libs/raphael-2.1.0/raphael.amd' 依赖项将所有其他内容加载到 raphael-2.1.0 目录中。如果我访问 app.local/src,该应用程序将按预期工作,它会在运行时通过 require 在我的 index.html 文件中使用单个脚本标记加载模块,如下所示:

<script src="js/libs/require-2.0.5.js" data-main="js/main.js" type="text/javascript" charset="utf-8"></script>

但是,如果我尝试从应用程序运行命令 node r.js -o src/build.js,我会收到如下错误:

Error: ERROR: module path does not exist: /app/src/main.js for module named: main. Path is relative to: /app
at /app/r.js:14215:31

...所有内容都“按原样”复制到 bin 中。如果我将'main': 'js/main' 添加到paths 对象,那么r.js 找不到jquery 和raphael,如果我将js/ 添加到jquery 和raphael 路径,那么libs/raphael-2.1.0/rapheal.amd 的依赖声明是错误的。如果我更新这些,那么一切都会按预期构建,但现在 app.local/src/index.html 上的应用程序已损坏。另外,我认为这就是在构建文件中具有 baseURL 属性的意义,不是吗?在我看来,baseURL 被忽略了。我做错了什么?

【问题讨论】:

  • 遇到同样的问题,快把我逼疯了!
  • @mysterycommand,你找到解决办法了吗?

标签: javascript build requirejs optimization


【解决方案1】:

与 JavaScript 中的大多数内容一样,baseUrl 设置区分大小写。将 URL 更改为 Url 看看是否有帮助。

【讨论】:

  • 我遇到了同样的“问题”。这不是一个真正的问题,但即使使用 baseUrl 也会被忽略。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 2016-09-30
  • 2012-03-11
  • 1970-01-01
  • 1970-01-01
  • 2015-05-28
相关资源
最近更新 更多