javascript - How can I fix this AMD path conflict? -
i trying use esri arggis javascript api, loaded dojo, using dojo.require
. have existing modular amd/requirejs typescript application need integrate code into. @ top of initial ts file, import several modules:
import tracer = module('../classes/trace'); import pubsub = module('../classes/pubsub'); import masker = module('../classes/masker'); // etc.
this working fine, have added arcgis code, instead of resolving relative path within application, require.js has picked baseurl esri site, , tries load:
http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/classes/trace.js // etc.
resulting in string of 404 responses , script errors.
how can fix this?
i've tried setting requirejs baseurl in head of html file before loading first document loads modules:
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3"></script> <script type="text/javascript" src="/content/client/libs/require.js"></script> <!-- data-main="/content/client/hop/hop.app" --> <script type="text/ecmascript"> require.config({ baseurl: "/content/client/hop/" }); </script> <script src="~/content/client/hop/hop.app.js"></script>
but fails, throwing exception require has no method config.
(nb if reverse order in head of html document arcgis api comes last in load sequence opposite problem - local files work fine dojo , mapping api fail because looking paths relative site when should searching on argis server).
i work esri's arcgis api i've run exact problem. this blog post dojo helped me out some.
the first issue dojo isn't configured same way requirejs is. looks defined dojoconfig set things up. second esri's module loading set assuming 1 basepath, , code going want another. you're going need dojo config looks this:
dojoconfig = { baseurl: location.pathname.replace(/\/[^/]+$/, '') + '/content/client/hop/', // magic! packages: [ { name: 'dojo', location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact/js/dojo/dojo/" }, { name: 'dojox', location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact/js/dojo/dojox" }, { name: 'esri', location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact/js/esri" } ] };
what doing setting basepath current url plus stuff, , telling dojo esri's stuff is. packages i've run if there's dependency missed because never loaded me, need similar entry.
another problem might run if you're used loading script locally file:// dojo domain going try access file:// , browser going shut right down. you'll need test on local http server on. on windows prefer hfs , on linux python makes easy.
i hope helps.
Comments
Post a Comment