RequireJS:根据环境加载不同的文件 [英] RequireJS: loading different files according environment
问题描述
是否具有根据当前项目环境(例如,开发或生产)加载不同文件的功能?我的意思是,这可以帮助我透明地加载缩小或完整的文件.我读过有关多版本加载的信息,但是多版本意味着我需要指定文件的版本.
例如,我的模块中有module.js文件.在此文件中,我需要加载jQuery:
Is there any functionality to load different files according on current project environment (development or production for example)? I mean something, that helps me transparently loading minified or full files. I read about multiversion loading, but multiversioning means that I need to specify version of file.
For example I have module.js file with my module. In this file I need to load jQuery:
require(['jquery]);
但是我已经缩小了jQuery的完整版,我想加载不同的文件.我正在考虑在config中这样的事情:
But I have minified and full version of jQuery and I want to load different files. I am thinking about something like this in config:
require.config({
paths: {
'jquery' : function(){
if( MODE == 'DEV' ){
return 'jquery';
}else{
return 'jquery.min'
}
}
}
});
或者,也许类似的东西.
Or, maybe, something similar.
推荐答案
如果有人仍然想知道该怎么做:
If someone still want to know how to do that:
require.config({
paths: {
'jquery' : (function(){
if( MODE == 'DEV' ){
return 'jquery';
}else{
return 'jquery.min'
}
})()
}
});
此功能是自调用匿名功能.它会在定义位置立即调用.
This function is self invoking anonymous function. It invokes immediately in the definition place.
这篇关于RequireJS:根据环境加载不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!