Is it possible to use Dojo build without modifying JS files?

放肆的年华 提交于 2019-12-11 03:31:58

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17787428/is-it-possible-to-use-dojo-build-without-modifying-js-files

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