@asgoth के answer निश्चित रूप से काम करेगा, लेकिन करने के साथ ही अन्य विकल्पों में से जोड़ी पता लगा 'इंजेक्षन' (या निर्माण प्रक्रिया के दौरान कोड को हटा दें) कोड।
example build.js file में प्रलेखित के रूप में, हम बिल्ड प्रक्रिया के दौरान कोड स्निपेट को शामिल/बहिष्कृत करने के लिए pragmas
निर्माण का उपयोग कर सकते हैं।
//Specify build pragmas. If the source files contain comments like so:
//>>excludeStart("fooExclude", pragmas.fooExclude);
//>>excludeEnd("fooExclude");
//Then the comments that start with //>> are the build pragmas.
//excludeStart/excludeEnd and includeStart/includeEnd work, and the
//the pragmas value to the includeStart or excludeStart lines
//is evaluated to see if the code between the Start and End pragma
//lines should be included or excluded. If you have a choice to use
//"has" code or pragmas, use "has" code instead. Pragmas are harder
//to read, but they can be a bit more flexible on code removal vs.
//has-based code, which must follow JavaScript language rules.
//Pragmas also remove code in non-minified source, where has branch
//trimming is only done if the code is minified via UglifyJS or
//Closure Compiler.
pragmas: {
fooExclude: true
},
//Same as "pragmas", but only applied once during the file save phase
//of an optimization. "pragmas" are applied both during the dependency
//mapping and file saving phases on an optimization. Some pragmas
//should not be processed during the dependency mapping phase of an
//operation, such as the pragma in the CoffeeScript loader plugin,
//which wants the CoffeeScript compiler during the dependency mapping
//phase, but once files are saved as plain JavaScript, the CoffeeScript
//compiler is no longer needed. In that case, pragmasOnSave would be used
//to exclude the compiler code during the save phase.
pragmasOnSave: {
//Just an example
excludeCoffeeScript: true
},
मैं jquery.mobile
code पर कार्रवाई, जो शायद से AMD
और requirejs
सीखने के लिए एक अच्छी जगह है में इस देख सकता था।
यहाँ क्या मेरे लिए काम किया है:
AppLogger.js:
/* global console: false */
define(function() {
var debugEnabled = false;
//>>excludeStart('appBuildExclude', pragmas.appBuildExclude);
debugEnabled = true;
//>>excludeEnd('appBuildExclude');
return {
log:function (message) {
if (debugEnabled && console) {
console.log('APP DEBUG: ' + message);
}
}
};
});
Gruntfile.js:
requirejs:{
compile:{
options:{
baseUrl:"js/",
mainConfigFile:"js/main.js",
name:'main',
out:'js/main.min.js',
pragmas:{ appBuildExclude:true }
}
}
}
requirejs
के लिए इस कॉन्फ़िगरेशन के साथ
मेरी Gruntfile
में ,के प्रागम्स के भीतर खंडऔर excludeEnd
संकलित/निर्मित फ़ाइल से अलग हो गए थे।
मैं अभी भी requirejs
सीख रहा हूं, इसलिए कोई दावा नहीं है कि यह इस तरह की चीज़ के लिए सबसे अच्छा अभ्यास है, लेकिन यह निश्चित रूप से मेरे लिए काम करता है।
आपके उत्तर के लिए धन्यवाद। जो मैं खोज रहा था वह थोड़ा अलग है और मैंने इसे प्रश्न के अपडेट के साथ स्पष्ट करने की कोशिश की है। –
मेरा जवाब संपादित किया गया। देखें कि क्या मदद करता है। – asgoth
यह निश्चित रूप से काम करेगा, लेकिन [r.js उदाहरण बिल्ड फ़ाइल] से [pragmas' बनाने का एक और विकल्प निकाला गया है (https://github.com/jrburke/r.js/blob/master/build/example.build .js)। यह जाहिर है कि 'jquery.mobile' [भी उपयोग करता है] (https://github.com/jquery/jquery-mobile/blob/master/js/jquery.mobile.events.js)। मैंने आपका जवाब स्वीकार कर लिया है, लेकिन मेरे लिए जो कुछ भी काम कर रहा है उसके साथ मेरा दूसरा जोड़ देगा। धन्यवाद! –