Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between require.config and requirejs.config

I'm trying to set up requirejs and then optimise it using r.js, but then I'm confuse with these method. I've used require.config() before, but then I saw they also have requirejs.config() and I don't know what's the difference. Sample code:

require.config({     baseUrl: 'js/lib',     paths: {         app: '../app'     } });  requirejs.config({     baseUrl: 'js/lib',     paths: {         app: '../app'     } }); 

They both do the same thing. And when I optimise it, the result is exactly the same. I want to know what's the difference? When should I use on or the other?

like image 549
Zendy Avatar asked Jun 06 '13 11:06

Zendy


People also ask

What is RequireJS config?

Advertisements. RequireJS can be initialized by passing the main configuration in the HTML template through the data-main attribute. It is used by RequireJS to know which module to load in your application. For instance − <script data-main = "scripts/main" src = "scripts/require.js"></script>

What is RequireJS used for?

RequireJS is a JavaScript library and file loader which manages the dependencies between JavaScript files and in modular programming. It also helps to improve the speed and quality of the code.

Is RequireJS still relevant?

RequireJS has been a hugely influential and important tool in the JavaScript world. It's still used in many solid, well-written projects today.

What is RequireJS shim?

As per RequireJS API documentation, shim lets you. Configure the dependencies, exports, and custom initialization for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value.


1 Answers

"requirejs" is just an alias to the same API, since "require" is used by other libraries. From the documentation:

If you just want to load some JavaScript files, use the require() API. If there is already a require() in the page, you can use requirejs() to access the RequireJS API for loading scripts.

Even though it makes no technical difference, just by convention I would stay with require.config unless you have a naming conflict with some other module loader.

Results as of 6-Jun-2013:

https://stackoverflow.com/search?q=require.config (609 results)

https://stackoverflow.com/search?q=requirejs.config (258 results)

like image 73
explunit Avatar answered Sep 28 '22 05:09

explunit