Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tips for migrating a javascript app to using AMD (eg requirejs)

I have a javascript project were most modules are using some third party libs as 'global' dependencies (in particular jquery and jquery plugins)

I would like to "clean" the project (to express all libraries as requirejs dependencies.), however this is in my case a large task (lots of files, lots of third-party libs).

How could I make the migration easier / quicker ?

  • Can I "fake" using amd dependencies by wrapping the third-party libs in modules that just load them (with the order! plugin ?)
  • Is it safe to mix modules that load third-party libs as modulesand modules that directly use the global ?
  • If I wanted to automate things, are there any tools could I use to 'parse' a requirejs module to tell me if a particular symbol is used ?

Edit : What I mean by my last question is "Would it be possible to automatically rewrite my js files so that hey explicitely import dependencies instead of relying on browser globals ?"

like image 877
phtrivier Avatar asked Sep 06 '12 12:09

phtrivier


People also ask

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.

Is RequireJS deprecated?

It is not deprecated. ESM modules (ECMAScript modules) that use import and export are the new Javascript standard for modules and we can expect that nodejs will support these for as long as they are the Javascript standard (probably forever).

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.


1 Answers

Can I "fake" using amd dependencies by wrapping the third-party libs in modules that just load them

Yes you can, RequireJS has a shim config that is designed just for that.

Take a look at this article it will help you organize your JavaScript code with RequireJS http://www.stefanprodan.eu/2012/09/intro-requirejs-for-asp-net-mvc/

like image 155
Stefan P. Avatar answered Nov 14 '22 21:11

Stefan P.