Requirejs's optimization tool----r.js

Source: Internet
Author: User

Requirejs is a JavaScript module loader that is based on the AMD specification.

R.js is a tool that it provides to package and build modules

Download R.js

Create a configuration file for R.js build.js

Build.js

({appdir:‘./‘,//Project root directoryOut :' Main-build.js ',//Output file name dir:'./outdir ',//output directory, folders to be placed after all files have been packaged (if not created automatically)      /*with Dir, you cannot use the Out configuration item, and you compile it with very specific hints*/BASEURL:'./js/pages ',//relative to Appdir, represents the starting folder to find the JS file, all the file path definitions are based on this baseurlmodules: [//The module to be optimized--the config item inside the page is the omitted suffix ". js" for the relative BaseURL path of the pages (the entry file----the file that was introduced when the page was loaded with the Data-main attribute specified by the Require.js script tag)       //This property is necessary because a program needs at least one entry{name:' Main '}, {name:' Index '}], Fileexclusionregexp:/^ (R|build) \.js|. *\.scss$/,//Regular matching filter file, matching to the file will not be output to the output directory, the filter out here is R.js, Build.js, *.scss three types of filesoptimizecss:' Standard ', removecombined:true,//If True, the optimizer removes the merged files from the output directorypaths: {//The paths of each module relative to the BaseURL can be baked directly from the require.config path configuration ."Underscore": ". /libs/underscore/underscore-min ",        "Backbone": ". /libs/backbone/backbone-min ",}, shim:{//Configure a module that does not conform to the AMD specification and can be grilled directly from the Require.config shim configuration"Underscore": {exports:"_"        },        "Backbone": {deps: ["Underscore", "jquery"], exports:"Backbone"        },    } })

The parameter attribute of the common build.js is explained:

R.js all the scripts needed for each page are integrated into the respective portal file (one or more JS), thereby reducing the request to the server.

Mainconfigfile: ' Common.js '//Multi-page complex engineering multiple inbound files of the unified require.config configuration placement file, relative BaseURL path

Because the multi-page project needs multiple inbound files, this time will appear the same require config in a project configuration multiple times, in order to avoid this problem, you can put the same config of multiple inbound files into a JS file, unified configuration,

And will use the Mainconfigfile parameter of the Build.js to redefine the module.

Examples can be consulted: Https://github.com/requirejs/example-multipage-shim

An easy-to-understand r.js packaging application Simple example: Http://www.tuicool.com/articles/iYNJbqZ

Http://www.cnblogs.com/vajoy/p/3920163.html#!/follow

Http://requirejs.org/docs/start.html

Requirejs's optimization tool----r.js

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.