是否可以使用Dojo构建而不修改JS文件? [英] Is it possible to use Dojo build without modifying JS files?

查看:139
本文介绍了是否可以使用Dojo构建而不修改JS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Dojo构建而不需要修改JavaScript文件?



文章 dgrid和Dojo Nano Build 提供了创建构建的指令,但需要将以下行添加到JavaScript文件初始化应用程序:

  require(['dgrid / dgrid'],function (){

(用你的构建模块名替换'dgrid / dgrid')。

但是,对于自己的模块使用build是非常有问题的,因为当然在开发模式下,不能包含自己的层的需求,否则对自己的模块进行修改但是在生产模式下,必须添加这一行。



所以你必须在生产生成之前手动修改文件,或者编写一个脚本来修改该文件在构建期间。两者都非常容易出错。



有没有更好的方式来实现这一结果? Dojo可以认识到构建是提供的,应该被使用,而不是单独加载每个模块?

解决方案

以下代码行可以包含在开发和生产模式中。

  require(['dgrid / dgrid'],function(){
/ pre>

我描述了为什么在我的回答中这里



您需要做的是根据什么环境配置Dojo。



在我写的博客帖子中,我以下总结了以下内容:



我创建了三种模式:生产,未压缩和开发。



开发



开发代码时,我将js的源码链接到Web服务器,而开发模式将指向dojo.js文件和原始的css文件,浏览器将加载我需要使用xhr的模块,我指向导入其他css文件的顶级css文件。结果是,将向服务器发出很多请求,并且页面的加载将显着变慢。好处是,您可以看到开发变更,而无需进行全面的构建。



生产



生产模式使用构建工具构建的 dojo.js 指向主dojo文件。我还为页面中需要的其他图层创建< script> 元素。我将CSS指向构建工具内置导入的CSS的内置css文件。该页面快速加载,但是很难调试



未压缩



类似到生产,但我指向.uncompressed.js文件。在我们的软件发布版本中提供了生产和未压缩版本。尝试解决生产环境中的问题时,我使用未压缩。这种模式的价值正在减弱,因为开发者工具更好地支持压缩的JavaScript(即源地图等)。



服务器端



默认模式是Production,但是我使用查询参数来切换模式。我也将当前模式存储在会话中,这样我只需要设置一次模式来改变它。后续页面将以更改的模式运行,直到我将其更改为止。



这里是这段代码的java实现。 >

Is it possible to use Dojo build without the need to modify JavaScript files?

The article dgrid and Dojo Nano Build provides the instruction to create the build, but it requires adding the following line into JavaScript file, which initializes the application:

require(['dgrid/dgrid'], function () { 

(replacing 'dgrid/dgrid' with your build module name).

However, it is very problematic when using build for own modules, because, of course, in development mode the require with own layer can't be included, otherwise the modifications made to own modules wouldn't be visible. But in production mode this line must be added.

So either you must modify the file manually before production build, or write a script that would modify the file during the build. Both are very error-prone.

Is there a better way to achieve that result? Is it possible for Dojo to recognize that the build is provided and should be used, instead of loading each module separately?

解决方案

The following line of code can be included in both development and production modes.

require(['dgrid/dgrid'], function () {

I describe the reasons why in my answer here.

What you need to do is configure Dojo differently based on what environment.

In a blog post that I wrote, I describe this in more detail. The following summarizes the post:

I create three modes: Production, Uncompressed, and Development.

Development

When developing code, I will have the js source linked into the web server and the Development mode will point to the dojo.js file and the raw css file(s). The browser will load modules that I need using xhr. And I point to the top level css files which import other css files. The result is that a lot of requests will be made to the server and the loading of the page will be noticeably slow. The benefit is that you can see development changes without having to do a full build.

Production

Production mode points the main dojo file at the dojo.js that is built using the build tool. I also create <script> elements for the other layers that are needed in the page. I point the css to the built css files which the build tool has inlined the imported css. The page loads quickly, but it is difficult to debug

Uncompressed

Similar to production, but I point to the .uncompressed.js files. Production and Uncompressed are available in the released version of our software. I use uncompressed when trying to troubleshoot an issue in a production environment. The value of this mode is dwindling as the developer tools are better supporting compressed javascript (ie source maps, etc.)

Server side

The default mode is Production, but I use a query parameter to switch modes. I also store the current mode in the session, so that I only have to set the mode once to change it. Subsequent pages will run in the changed mode, until I change it back.

Here is a java implementation of this code.

这篇关于是否可以使用Dojo构建而不修改JS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆