Requirejs Modular Post-JS compression merge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.