phtrivier
phtrivier

Reputation: 13415

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 ?

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 ?"

Upvotes: 6

Views: 921

Answers (2)

Stefan P.
Stefan P.

Reputation: 9519

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/

Upvotes: 1

Andreas Köberle
Andreas Köberle

Reputation: 111042

I had a similar question about the need of wrapping third party code in AMD modules. My conclusion was, that there are no benefits in my case (large Backbone app). So you should ask yourself if you really need to import jquery for example per AMD. This will end in modules where you import jquery every time, which is a lot of error prone boilerplate code.

So in short it makes no sense to use AMD for code that you will use in any case.

Upvotes: 0

Related Questions