2016-08-25 8 views
1

내 dojo 앱에서 동적으로 모듈을로드하려고하는데, 이는 내 코드를 빌드하기 전까지 작동합니다. 일단 dojo 빌드 시스템을 사용하여 코드를 빌드하면 어떻게 든 동일한 모듈이 모듈 자체가 아닌 interger (특히 3)로로드됩니다. 다음은 Dojo는 모듈 대신에 로딩 번호가 필요합니다.

은 다음과 같은 도장 빌드 시스템을 통해 왔을 때 이제 동일한 코드 조각을 응용 프로그램

var loadModule = "MyModule.js"; 
var path = "./js/path/to/MyModule/"; 
require([path+loadModule], lang.hitch(this,function (myModule) { 
    //do something with myModule 
    //this works without any problem 
})) 

을 구축하기 전에, 즉 작동 코드가됩니다 뭔가하고

var _23 = "MyModule.js"; 
var _24 = "./js/path/to/MyModule/"; 
require([_24 + _23], _2.hitch(this, function(_25) { 
    //here this '_25' is number 3 instead of myModule. which i wonder why! 
})) 
작동하지 않습니다 내가 사용하고있는 도장 빌드 시스템에 대한

다음과 같은 구성

layerOptimize: "shrinksafe", 
optimize: "shrinksafe", 
cssOptimize: "comments", 
mini: true, 
stripConsole: "warn", 
selectorEngine: "lite", 

편집 : 여기 내 응용 프로그램에서 동적으로로드하려고하는 모듈은 openlayers 맵을 처리 할 책임이 있습니다. 이 모듈의 기본 코드는 다음과 같습니다.

define(["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/window", "dojo/dom", "dojo/dom-construct", "dojo/topic","dojo/dom-style","dojo/on", 
     "dijit/registry","dijit/Tooltip","dijit/TooltipDialog","dijit/popup","dijit/ConfirmDialog", 
     "dojox/collections/Dictionary" 
     ], 
     function(declare, lang, baseWindow, dom, domConstruct, topic, domStyle, on, 
       registry,Tooltip,TooltipDialog,dijitPopup,ConfirmDialog, 
       Dictionary){ 

    var olMapModule = {}; 

    olMapModule.initMap = function(){ 
     //Code for openlayer go here  
    }; 


    olMapModule.initMapInteractions = function(){ 
     //code for initiating the map interactions go here 
    }; 
    return olMapModule; 
}); 

편집 2 : 쉼표가 실수로 삽입되었습니다. 또한이 코드는 도장 빌드를 수행하기 전에 완벽하게 작동합니다.

+0

동일한 컴퓨터에서 빌드 된 코드를 실행합니까? 나는 Windows 용 dev 및 Linux 용 빌드를 사용했을 때 ... 케이스에 실수가있었습니다 ... 위의 하나 대신 소문자 – ben

+0

동일한 컴퓨터에 있지 않지만 동일한 OS에서 즉 우분투를 사용합니다. dev뿐만 아니라 기계를 구축합니다. 또한 빌드 프로세스는 생산 중단을 위해 도장 빌드를 래핑하는 메이븐 플러그인을 사용하여 자동화됩니다. – Suraj

+0

''dojox/collections/Dictionary ''다음에 여분의 쉼표가있을 수 있습니다 (IE에서) 그러나 더 일반적으로 "3"은 몇 가지 이유가 있습니다 : 모듈을 요청할 때 404 또는 모듈을 평가할 때 JS 오류 – ben

답변

0

'require`를 사용할 때 문자열 연결을 피하십시오. 하나의 문자열에서 modeul의 경로를 지정하십시오. 이 문제를 해결해야합니다 :

require(["./js/path/to/MyModule/MyModule.js"], lang.hitch(this,function (myModule{})); 
+0

그냥 이것을 시도했지만 작동하지 않습니다. 아직 'myModule'대신 '3'이 표시됩니다 – Suraj

+0

@Suraj 모듈에 대한 질문 내용을 게시 할 수 있습니까? – GibboK

+0

미안하지만 마지막 의견을 얻지 못했습니다. 'myModule'의 코드/콘텐츠를 게시 하시겠습니까? – Suraj