gpt4 book ai didi

javascript - RequireJS/r.js 'baseURL' 属性看似被忽略

转载 作者:数据小太阳 更新时间:2023-10-29 05:39:00 24 4
gpt4 key购买 nike

我正在尝试使用 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' 添加到路径对象,然后 r.js 找不到 jquery 和 raphael,如果我将 js/ 添加到jquery 和 raphael 路径然后 libs/raphael-2.1.0/rapheal.amd 的依赖声明是错误的。如果我更新它们,那么一切都会按预期构建,但现在 app.local/src/index.html 上的应用程序已损坏。另外,我认为构建文件中有一个 baseURL 属性不是吗?在我看来,baseURL 被忽略了。我做错了什么?

最佳答案

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

关于javascript - RequireJS/r.js 'baseURL' 属性看似被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11926461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com