我有一个看起来像这样的文件结构:
/js
|-module/myModule.js
|-test.js
/vendor/
/spec
|-main.js
|-js/app.js
spec/main.js
是我的入口点,我从中加载模块/js,
/vendor
,/spec
我可以毫无问题地加载 invendor
和 in 的模块,spec
因为这些模块是假设baseUrl = '/'
.
我在加载模块时遇到问题,/js
因为这些模块是在假设baseUrl = '/js'
.
如何在不更改脚本代码的情况下解决此问题'/js'
?
这是一个示例,其中包含描述问题的内联注释。
规范/main.js
(function () {
'use strict';
require.config({
baseUrl: '../'
});
});
define([
'spec/js/app' // it works
], function (app) {
'use strict';
app.initialize();
});
规范/js/app.js
(function(){
'use strict';
define([
'js/module/myModule' // it works
], function () {
// some code
});
});
js/模块/myModule.js
(function(){
'use strict';
define([
'test' // it does not works because
// it assumes that baseUrl equals '/js' and not '/'
], function () {
// some code
});
});