我正在尝试学习如何使用require.js
加载我的脚本,但我的设置/理解有问题。我看不出有什么问题。使用我缺少的设置非常简单。
当我在Chrome中加载此index.html
页面时,没有任何脚本require.js
操作正在运行。
*** index.html的
<html>
<head>
<title>My Sample Project</title>
</head>
<body>
<h1 class="h1">sample project header</h1>
<script data-main="main" src="require.js"></script>
</body>
</html>
*** main.js
(function() {
requirejs.config({
//By default load any module IDs from baseUrl
baseUrl: '',
// paths config is relative to the baseUrl, and
// never includes a ".js" extension
paths: {
'small-blue-mod': './a-script'
}
});
// Start the main app logic.
requirejs(['small-blue-mod'], function (sbm) {
alert(sbm.color);
});
})();
***小蓝mod.js
define({
color: "blue",
size: "small"
});
*文件系统看起来像......
index.html
main.js
require.js
FOLDER called "a-script"
a-script
文件夹包含small-blue-mod.js
答案 0 :(得分:1)
路径small-blue-mod
是指a-script
文件夹,要么像small-blue-mod/small-blue-mod
那样需要,要么建议更改路径:
paths: {
'small-blue-mod': './a-script/small-blue-mod'
}