可以跳过带有r.js构建的内向的,名为modules?
-
21-12-2019 - |
题
在我的应用程序中,我有一个命名模块在index.html中定义了内联:
<script>
define('config', {
mode: '...',
environment: '...',
apiUrl: '...',
rootPath: '...',
baseImageUrl: '...'
});
</script>
.
我需要在我的网页中定义它,因为我在使用环境变量时提取一些东西。所以,在我的模块中,我可以包括'config':
define(['config', 'jquery'], function(config, $) { ... });
.
当我使用grunt运行reastjs构建时(使用 grunt-carry ,它使用r。js),它抱怨它没有找到config.js。我的构建配置如下所示:
{
baseUrl: 'js',
main: 'app/Main',
dir: 'js/build',
out: null,
modules: { ... },
paths: { ... },
shim: { ... }
}
.
当我构建时,我得到:
Error: Error: ENOENT, no such file or directory '/projects/projectname/js/build/config.js
.
如何与R.JS构建结合使用命名,内联定义模块?
解决方案
设置
paths: {
config : 'empty:'
}
.
在构建配置文件中应从优化过程中排除此模块,结果,请停止提高此错误。
但这有点棘手的方式,因为这个选项通常用于排除第三方依赖项(例如,在基于骨干网上开发一些JS库时,最好将lib与骨干分开)
不隶属于 StackOverflow