3

I would like to create a (require.js style) AMD module that can be used in the browser and in node. What is the best way to do this? I keep seeing references to r.js, but still not 100% sure on how to use it, or if it is necessary for my situation.

Also, when including this module in node, do I still run require('module-name'), or will this change as well?

1

1 Answer 1

2

First things first: AMD basics, What all you can do with them, How to optimize them

In extremely simple terms

  • AMD modules are reusable JS code. Think of them as functions kept in separate files.
  • AMD loaders are central functions which call all other functions (modules). Think of them as "main" method in C or Java.
  • RequireJS is a framework which pulls all this scattered code and stitches it in a usable form.
  • RequireJS works in a browser. As a result, all your code is "stitched" together in a web browser.
  • r.js works offline (in a web server or on your development machine) to "stitch" all the code offline so that when it reaches a web browser, it's already "stitched".
  • Use of RequireJS lib is a must no matter you want to "stitch" your code in browser or you want to serve your code "pre-stitched".
  • Use of r.js is optional. It's needed only if you want to increase performance and decrease HTTP calls.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.