我最近遇到了几个令人恼火的情况,我们的Require配置的paths
对象在requirejs.dist.options.paths
中的Grunt实例化与我们的前端引导程序(main.js
)之间不同步传递给paths
的{{1}}属性。
为了避免咕噜咕噜的工作,我想将require.config( paths: { /* etc */ } } )
保存为文件paths
中的JSON对象。
我在require_config_paths.json
中掌握了JSON,如下所示:
Gruntfile.js
在requirejs: {
dist: {
options: {
paths: grunt.file.readJSON( '/assets/js/src/require_config_paths.json' )
}
}
};
中做什么是煎饼。我目前最终得到以下内容:
main.js
但是设置// Temporary config to circumvent error when I Require the JSON later on:
// Cannot optimize network URL, skipping: require_config_paths.json?define
require.config( {
paths: {
'require_config_paths.json?define' : 'empty:'
}
} );
// Require the JSON: handle as JSONP via define callback and pass as `paths`
require( [ 'require_config_paths.json?define' ], function configureR( paths ){
require.config( {
paths: paths
} );
} );
的尝试没有做任何事情 - 它仍然被跳过,因为无法优化网络网址 - 这是一个奇怪的抱怨,因为资源隐含地是本地资源。
答案 0 :(得分:0)
empty:
是您希望仅放入传递给r.js
的构建配置中的内容。您不要将它放在HTML或HTML加载的文件中。
在您的情况下,这意味着将empty:
的{{1}}设置放在'require_config_paths.json?define'
内。我意识到它将在运行时加载,然后将使用'/assets/js/src/require_config_paths.json'
覆盖'require_config_paths.json?define'
的设置,但到那时它应该无关紧要。