में बिल्ड आउटपुट पथ सेट करने के लिए ग्लोबल वेरिएबल का उपयोग करें मेरे पास कुछ गड़बड़ कार्य हैं और मैं उन कार्यों में वैश्विक चर साझा करने की कोशिश कर रहा हूं और मैं मुद्दों पर चल रहा हूं।ग्रंट
मैंने कुछ कस्टम कार्य लिखे हैं जो निर्माण प्रकार के आधार पर उचित आउटपुट पथ निर्धारित करते हैं। ऐसा लगता है कि चीजों को सही ढंग से सेट करना है।
// Set Mode (local or build)
grunt.registerTask("setBuildType", "Set the build type. Either build or local", function (val) {
// grunt.log.writeln(val + " :setBuildType val");
global.buildType = val;
});
// SetOutput location
grunt.registerTask("setOutput", "Set the output folder for the build.", function() {
if (global.buildType === "tfs") {
global.outputPath = MACHINE_PATH;
}
if (global.buildType === "local") {
global.outputPath = LOCAL_PATH;
}
if (global.buildType === "release") {
global.outputPath = RELEASE_PATH;
}
if (grunt.option("target")) {
global.outputPath = grunt.option("target");
}
grunt.log.writeln("Output folder: " + global.outputPath);
});
grunt.registerTask("globalReadout", function() {
grunt.log.writeln(global.outputPath);
});
तो, मैं बाद में कार्य में वैश्विक.outputPath का संदर्भ देने और त्रुटियों में चलने का प्रयास कर रहा हूं।
यदि मैं कमांड लाइन से grunt test
पर कॉल करता हूं, तो यह सही पथ को कोई समस्या नहीं देता है।
हालांकि, मैं अगर इस तरह एक कार्य: साफ: { रिहाई: { src: global.outputPath } }
यह निम्न त्रुटि फेंकता है: Warning: Cannot call method 'indexOf' of undefined Use --force to continue.
इसके अलावा, setOutput कार्य में मेरे स्थिरांक मेरे Gruntfile.js
किसी भी विचार के शीर्ष पर सेट हैं? क्या मुझसे यहां कुछ गलत हो रहा है?
मुझे लगता है कि यह वैश्विक.outputPath से संबंधित हो सकता है grunt.initConfig ({}) के बाहर सेट किया जा रहा है, जबकि, मैं grunt.initConfig के अंदर चर का उपयोग करने की कोशिश कर रहा हूं ({}) – ThePuzzleMaster