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?
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>
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.
RequireJS has been a hugely influential and important tool in the JavaScript world. It's still used in many solid, well-written projects today.
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.
"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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With