After using REQUIREJS modular code is split into multiple JS files, in the deployment of production environment requires compression merge, Requirejs provides a packaging compression tool r.js to the module to merge compression. R.js is very powerful and can not only compress js,css, but even package the entire project.
The R.js compression tool uses UGLIFYJS or closure Compiler. UGLIFYJS is used by default (jquery also uses it for compression). In addition, R.js requires the node. JS environment, and of course it can also run in Java environments such as Rhino. The Java environment uses ant build to refer to another Requirejs optimizer ant task. Node Environment Reference REQUIREJS Modular and Gruntjs construction.
This article describes the methods described in the official Require.js documentation.
Build.xml
{ appDir: ‘../www‘ , baseUrl: ‘js/lib‘ , paths: { app: ‘../app‘ }, dir: ‘../www-built‘ , modules: [ //First set up the common build layer. { //module names are relative to baseUrl name: ‘../common‘ , //List common dependencies here. Only need to list //top level dependencies, "include" will find //nested dependencies. include: [ ‘jquery‘ , ‘app/lib‘ , ‘app/controller/Base‘ , ‘app/model/Base‘ ] }, //Now set up a build layer for each page, but exclude //the common one. "exclude" will exclude nested //the nested, built dependencies from "common". Any //"exclude" that includes built modules should be //listed before the build layer that wants to exclude it. //"include" the appropriate "app/main*" module since by default //it will not get added to the build since it is loaded by a nested //require in the page*.js files. { //module names are relative to baseUrl/paths config name: ‘../page1‘ , include: [ ‘app/main1‘ ], exclude: [ ‘../common‘ ] }, { //module names are relative to baseUrl name: ‘../page2‘ , include: [ ‘app/main2‘ ], exclude: [ ‘../common‘ ] } ] } |
You can compress a merge module by executing node R.js-o build.js in the node environment.
Project Reference Https://github.com/requirejs/example-multipage/blob/master/tools/build.js
Requirejs Modular Post-JS compression merge