如何在构建期间重命名全局dojo,dijit和dojox全局变量(dojo 1.8.x)(how to rename the global dojo, dijit & dojox global var

编程入门 行业动态 更新时间:2024-10-28 14:34:15
如何在构建期间重命名全局dojo,dijit和dojox全局变量(dojo 1.8.x)(how to rename the global dojo, dijit & dojox global variables during build time (dojo 1.8.x))

我们计划将dojo 1.8与旧版本(1.2)一起使用。 我们希望全局变量dojo指向dojo的1.2版本,dojo18指向1.8版本。 我尝试使用dojoConfig的packages属性来使其工作。

<script type="text/javascript" src="<some_path>/dojo-release-1.2.0/dojo/dojo.js" djConfig="parseOnLoad: true"></script> <script> djConfig = {}; var dojoConfig = { parseOnLoad: true, async: true, baseUrl: '<some_path>/dojo-release-1.8.3/dojo', packages: [ {name: 'dojo18', location: '<some_path>/dojo-release-1.8.3/dojo', packageMap: { dojo: 'dojo18', dijit: 'dijit18', dojox: 'dojox18' } }, {name: 'dijit18', location: '<some_path>/dojo-release-1.8.3/dijit'}, {name: 'dojox18', location: '<some_path>/dojo-release-1.8.3/dojox'}, ], deps: ["dojo18", "dijit18", "dojox18"] }; </script> <script src="/cuic/scripts/dojo-release-1.8.3/dojo/dojo.js"></script>

然而,这似乎不起作用 - 现在有两个全局变量--dojo和dojo18 - 两者都指向1.8版本的Dojo。

由于Dojo的编译版本的包的重定位不起作用,我想知道是否有任何构建属性暴露,通过执行dojo的自定义构建将dojo更改为dojo18,dijit到dijit18,dojox到dojox18。

We are planning to use dojo 1.8 alongside with a legacy version (1.2). We want the global variable dojo to point to 1.2 version of dojo and dojo18 to point to 1.8 version. I tried using the packages attribute of dojoConfig to get this to work.

<script type="text/javascript" src="<some_path>/dojo-release-1.2.0/dojo/dojo.js" djConfig="parseOnLoad: true"></script> <script> djConfig = {}; var dojoConfig = { parseOnLoad: true, async: true, baseUrl: '<some_path>/dojo-release-1.8.3/dojo', packages: [ {name: 'dojo18', location: '<some_path>/dojo-release-1.8.3/dojo', packageMap: { dojo: 'dojo18', dijit: 'dijit18', dojox: 'dojox18' } }, {name: 'dijit18', location: '<some_path>/dojo-release-1.8.3/dijit'}, {name: 'dojox18', location: '<some_path>/dojo-release-1.8.3/dojox'}, ], deps: ["dojo18", "dijit18", "dojox18"] }; </script> <script src="/cuic/scripts/dojo-release-1.8.3/dojo/dojo.js"></script>

This however doesn't seem to work - now there re 2 global variables - dojo and dojo18 - both of which point to 1.8 version of Dojo.

Since relocation of packages of compiled version of Dojo is not working, I was wondering if there are any build properties exposed that change dojo to dojo18, dijit to dijit18, dojox to dojox18 by doing a custom build of dojo.

最满意答案

这是在黑暗中完全拍摄的......

.8调用创建一个dojo实例..这是正常的......它会杀死你的旧道场。

尝试在实例化之后立即将第1行中创建的dojo对象克隆到另一个变量。 然后,在该过程的其余部分之后,将1.8 dojo实例也克隆到另一个变量。

最后将新变量分别克隆回dojo和dojo18 ......

没有承诺,但是在你太深入之前你可以尝试一下,我也有兴趣看看它是否有效。 如果它确实有效,你也应该能够为第一个实例使用djConfig,为第二个实例使用dojoConfig ......

对不起......我在手机上,所以无法测试:) ...

后来..一个非常邋test的测试,但是这个工作......

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.4.3/dojo/dojo.xd.js"></script> <script type="text/javascript" >var dojette = dojo;</script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script> <script type="text/javascript" >var dojo18 = dojo;</script> <script type="text/javascript" >var dojo = dojette; console.log(dojo.version); console.log(dojo18.version); </script>

如果你将dojo和dojo18作为完整的对象转储,你会发现它们已经完成了函数等。我没有进一步分离模块名称空间等,所以我的其余代码仍然爆炸,但它是一个开始......我希望它有所帮助......

I got the custom build to create a global variable 'dojo18', 'dijit18' 'dojox18' - by modifying the dojo/_base/kernel code's scopeMap variable.

var scopeMap = // a map from a name used in a legacy module to the (global variable name, object addressed by that name) // always map dojo, dijit, and dojox { dojo:["dojo18", dojo], dijit:["dijit18", dijit], dojox:["dojox18", dojox] },

This configuration ensures that the global variables will be named as 'dojo18' instead of 'dojo'. The scopeMap variable seems to be respected in the earlier versions of dojo, when provided via the dojoConfig variable. But it doesn't seem to work in 1.8.x versions. I wonder if this is no longer supported.

更多推荐

本文发布于:2023-08-01 06:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1354310.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   重命名   全局变量   如何在   variables

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!