How to locally test cross-domain builds?

筅森魡賤 提交于 2020-02-24 09:58:31

问题


Using the dojo toolkit, what is the proper way of locally testing code that will be executed as cross-domain, without making the actual build?

As it appears, there are three possible options (each, with their own drawbacks):

  1. Using local (non xd) XMLHttpRequest dojo.require
    • This option does not really test the xd behavior, since it dojo.require[s] the js synchronously via XHR.
  2. djConfig.debugAtAllCosts = true;
    • Although this option does load the required code asynchronously (via the 'script' tag), it also pulls the code in via XHR, parses the dojo.require[s] inside that, and pulls them in. This (using the loader_debug), again, is not what the loader_xd is doing. More info on this topic in a different question.
  3. Creating a cross-domain build
    • This approach requires a build, which is not possible in the environment which I'm running the code in (We're using our own on-the-fly build process, which includes only the js that is necessary for a particular page. This process is not suitable for development).

Thus, my question: is there a way to use the loader_xd, which does not require an xd build (which adds the xd prefix / suffix to every file)?

The 2nd way (using the debugAtAllCosts) also makes me question the motivation for pre-parsing the dojo.require[s]. If the loader_xd will not (or rather can not) pre-parse, why is the method that was created for testing/debugging doing so?


回答1:


I don't think there's any way to do XD loading without building and deploying it. Your analysis of the various options seems about right.

debugAtAllCosts is there specifically to solve a debugging problem, where most browsers, until recently, could not do anything intelligent with code brought in through eval. Still today, Firefox will report exception in the console as appearing at the eval site (bootstrap.js) with a line number offset from the eval, rather than from the actual eval buffer, and normally that eval buffer is anonymous. Firebug was the first debugger to jump through some hoops to enhance the debugging experience and permitted special metadata that Dojo's loader injects between the XHR and the eval to determine a filepath to the source. Webkit/Safari have recently implemented this also. I believe debugAtAllCosts pre-dates the XD loader.




回答2:


peller has described the situation. If you wanted to just generate .xd.js file for your modules, you could look at util/buildscripts/jslib/buildUtilXd.js and its buildUtilXd.xdgen() function.

It would take a bit of work to make your own script, but you could look at util/buildscripts/build.js for pointers.

I am hoping in the future for Dojo (maybe Dojo 2.x timeframe) we can switch to a loader that just uses script tags with a module format that has a function wrapper around the module, something that is coded by the developer. This would allow the same module format to work in the local and xd cases.



来源:https://stackoverflow.com/questions/1922351/how-to-locally-test-cross-domain-builds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!