RequiredJS 无法加载 JS 文件
RequiredJS failed to Load a JS file
我在 RequiredJS 中有这个简单的示例并尝试加载 jQuery 文件但抛出错误。我做错了什么?
层次结构
index.html
scripts/
libs/
jquery.js
compute/
config.js
requirejs.config({
baseUrl: 'scripts/libs'
});
requirejs(['jquery'],
function(sub) {
console.log(sub);
});
SCRIPT5022: Script error for "jquery"
http://requirejs.org/docs/errors.html#scripterror require.js (7,175)
像下面这样的东西对我有用:
requirejs.config({
// Path mappings for the logical module names
paths: (function () {
var pathObj = {};
pathObj = {
'jquery': '../your/path/to/js/libs/jquery/jquery-3.1.1.min'
};
return pathObj;
})(),
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
}
}
});
require(['jquery'],
function ($) {
$.ajax({/*some ajax call for example */});
}
);
我在 RequiredJS 中有这个简单的示例并尝试加载 jQuery 文件但抛出错误。我做错了什么?
层次结构
index.html
scripts/
libs/
jquery.js
compute/
config.js
requirejs.config({
baseUrl: 'scripts/libs'
});
requirejs(['jquery'],
function(sub) {
console.log(sub);
});
SCRIPT5022: Script error for "jquery" http://requirejs.org/docs/errors.html#scripterror require.js (7,175)
像下面这样的东西对我有用:
requirejs.config({
// Path mappings for the logical module names
paths: (function () {
var pathObj = {};
pathObj = {
'jquery': '../your/path/to/js/libs/jquery/jquery-3.1.1.min'
};
return pathObj;
})(),
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
}
}
});
require(['jquery'],
function ($) {
$.ajax({/*some ajax call for example */});
}
);