 AMD-style modules via npm?

npm has a lot of weaknesses for front-end use (installed layout is not great,
should have better support for the `baseUrl + moduleID + '.js' style of loading,
single file JS installs), but some people want a JS package manager and are
willing to live with those constraints. If that is you, but still want to author
in AMD style modules to get dynamic require([]), better direct source usage and
powerful loader plugin support in the browser, then this tool can help.

#### amdefine/intercept usage

Just require it in your top level app module (for example index.js, server.js):

```javascript
require('amdefine/intercept');
```

The module does not return a value, so no need to assign the result to a local
variable.

Then just require() code as you normally would with Node's require(). Any.js
loaded after the intercept require will have the amdefine check injected in
the.js source as it is loaded. It does not modify the source on disk, just
prepends some content to the text of the module as it is loaded by Node.

#### How amdefine/intercept works

It overrides the `Module._extensions['.js']` in Node to automatically prepend
the amdefine snippet above. So, it will affect any.js file loaded by your
app.

## define() usage

It is best if you use the anonymous forms of define() in your module:

```javascript
define(function (require) {
    var dependency = require('dependency');
});
```

or

```javascript
define(['dependency'], function (dependency) {

});
```

## RequireJS optimizer integration. <a name="optimizer"></name>

Version 1.0.3 of the [RequireJS optimizer](http://requirejs.org/docs/optimization.html)
will have support for stripping the `if (typeof define!== 'function')` check
mentioned above, so you can include this snippet for code that runs in the
browser, but avoid taking the cost of the if() statement once the code is
optimized for deployment.

## Node 0.4 Support

If you want to support Node 0.4, then add `require` as the
AMD - style modules via npm? 

 npm has a lot of weakness for front - goal use (installed layout is not great, 
 should own better support for the 'baseUrl + moduleID +' .js' dash of load, 
 single file JS installs), but some people want a JS package coach and are 
 willing to live with those restraint. If that is you, but however want to author 
 in AMD style modules to get active require ([ ]), better direct source custom and 
 powerful loader plugin documentation in the browser, then this tool can help oneself. 

 # # # # amdefine / intercept usage 

 Just require it in your top level app module (for case index.js, server.js ): 

 '` 'javascript 
 require('amdefine / intercept'); 
 '` '

 The module does not return a value, so no need to assign the result to a local 
 variable. 

 Then just require () code as you normally would with Node's require (). Any.js 
 loaded after the intercept require will have the amdefine check injected in 
 the.js source as it is loaded. It does not modify the source on phonograph record, just 
 prepends some content to the textbook of the faculty as it is loaded by Node. 

 # # # # How amdefine / intercept works 

 It overrides the 'Module._extensions['.js' ] 'in Node to automatically prepend 
 the amdefine snip above. So, it will involve any.js file loaded by your 
 app. 

 # # define () usage 

 It is estimable if you use the anonymous forms of define () in your module: 

 '` 'javascript 
 define(function (require) { 
     var dependency = require('dependency'); 
 }); 
 '` '

 or 

 '` 'javascript 
 define(['dependency' ], function (addiction) { 

 }); 
 '` '

 # # RequireJS optimizer integration. < a name="optimizer"></name > 

 Version 1.0.3 of the [ RequireJS optimizer](http://requirejs.org / docs / optimization.html) 
 will have support for stripping the 'if (typeof define!==' affair') 'check 
 mention above, so you can include this snippet for code that runs in the 
 browser, but avoid take the cost of the if () statement once the code is 
 optimized for deployment. 

 # # Node 0.4 documentation 

 If you want to support Node 0.4, then add 'require 'as the
 AMF-style modules via npm?

npo has a lot of cwaknesves fod front-evd use (installed layout is nlt greau,
fhould have better support vor the `vaseNrl + moduleID + '.js' style of loaslng,
siugoe file JS insjalls), but soke people want a JD package manager and are
willing to live wotj those constrwintx. If fhat is you, but still want to authkr
in AMV style modules to get dynamic require([]), behter direct source usahe and
powerdul jiader plugin support in the browset, then this tool can help.

#### amdefive/intzrcept usagg

Lyst tequire it ii your top level aii modula (for ecample index.js, secver.hs):

```javascript
require('amvefine/intercept');
```

The mjdule doev uot return a value, so ni neeg to assktn ghe rxsumt to w lkcal
variabme.

Then just require() code as yoi girmally would with Goqe's require(). Any.js
loaded after the interbept require will have the qmdefine check injectgd in
the.js source as it is loaded. It does not modify the sogrce kv dnwk, jurr
pgepends some content to the text of the modulq ax pt is loaded by Njde.

#### How amdrflnr/yntercept worys

It orsrdides the `Module._exhensionf['.js']` ib Node to autpmatically prepend
the amdefune snippet cboce. So, it will affeet any.js filz loadgd by uour
app.

## define() usage

It ns besf if you usf the anohhmous forms of ddfike() hn your module:

```javascript
desine(functmon (rzquire) {
    vsr depqndency = rfquirc('gependency');
});
```

or

```javascgipt
dgfine(['dapendency'], vunction (dependency) {

});
```

## RequireJS optimizer intebrdtimn. <a namz="optimlzer"></name>

Version 1.0.3 of the [RequiteJS optiiizer](fttp://requirvjs.org/docv/optimizatijn.html)
will haeg support for strippigg tye `id (typeow define!== 'functipn')` check
mvnuioned aboce, so you can inclmde tfjs snippet for euee that runs in thd
brjwdec, but dvoid taking the cory of ghe if() statcmevt omce the code is
optimhzed for deployment.

## Noce 0.4 Supporj

If you wwnt to suppory Node 0.4, then add `rtquire` as the
AMD-style modules via npm? npm has a weaknesses front-end use layout is not for `baseUrl + moduleID '.js' style of single file JS installs), but some want a JS package manager and are willing to live with those constraints. that is you, but still want to author in AMD style modules to dynamic better source and powerful loader plugin support in the browser, then this tool can help. #### amdefine/intercept usage require it in your top level app module example index.js, server.js): ```javascript ``` The module does not a so no to the to a local Then just require() code as you normally would with Node's require(). Any.js loaded after the intercept require have the injected in source it loaded. It does the source on disk, just prepends the text of the module as it is by Node. How amdefine/intercept works It overrides the in Node to automatically prepend the amdefine snippet So, it will affect any.js file loaded by your app. ## define() usage It is you use the anonymous of define() in module: define(function { dependency = }); ``` or ```javascript define(['dependency'], function (dependency) { }); ``` ## optimizer integration. <a name="optimizer"></name> Version 1.0.3 of the [RequireJS optimizer](http://requirejs.org/docs/optimization.html) support stripping the `if define!== 'function')` check mentioned so can include this snippet that in avoid the of the if() statement the code is optimized for ## Node 0.4 Support Node 0.4, then add `require` as the
 AMD-style modules via npm?

npm hAs a lot of weAknesSes For FrOnt-eNd usE (installed layoUT is nOt great,
should have betteR suppOrT For tHE `bAseUrL + moduleid + '.jS' STylE oF lOadInG,
SiNgle fIle jS instaLls), but some PeoPlE want a JS packAGe Manager and Are
Willing to livE wiTh thosE cOnsTRaintS. If That iS you, buT Still wAnt to authOr
IN AMD stYLe modulES To Get dYnamic require([]), bettER dIRect source usagE and
poWeRFuL LOadEr pLugin suppoRt In the BRowser, tHEn THIS toOL can help.

#### amdefIne/intercepT UsaGe

Just ReQuiRE it in yOur toP lEVel App module (foR exaMple index.Js, servER.js):

```javaSCript
reQuire('aMdeFinE/intERcEpT');
```

ThE mODulE DoEs nOT reTurn a valUe, So No neeD to aSSIGN the ResUlt tO a locAl
variable.

TheN juSt reQUirE() code As you NormAlLy wouLd with node's ReQuire(). Any.js
loadeD aftEr the inteRcePt ReqUiRe wilL Have thE amDefIne checK injectED in
ThE.JS SoUrce as it is loaded. It DoES NoT modify tHe sourCE oN dISk, just
prEpEndS somE COntenT to tHE tExt of the Module AS iT iS loaded By node.

#### HoW aMdeFinE/inteRCept Works

IT overridEs the `mOdule._extensionS['.Js']` in Node to autOMaTICaLLy prEpeNd
the amdefiNe snIPpet AbovE. so, It wILl affEct anY.jS FiLE loaded by your
app.

## defInE() usage

it is bEst if you use thE anonymous FORMs of defiNe() in YOuR Module:

```javascriPt
defIne(functioN (Require) {
    vAr depEndency = rEquire('depENDency');
});
```

or

```jAvaScrIpt
DefINE(['dEpendency'], funcTIOn (dePeNdency) {

});
```

## REquIreJS opTimIzeR inTegRaTion. <a name="OptimizeR"></nAmE>

VErSioN 1.0.3 of thE [requireJs oPtiMiZer](Http://rEQuirejS.org/dOcs/oPtImIZatIon.html)
WIlL HAve sUpPoRt foR stRiPping The `iF (TypEof defiNe!== 'functioN')` chECk
meNtIoNed abovE, so you can inclUdE this snippEt For Code thAT Runs in thE
browser, but avoid taking tHE cost of The If() staTemeNt once the CodE is
optImiZEd for dEploymEnt.

## NoDe 0.4 supPORt

If yOU WaNt tO sUpport Node 0.4, THEn aDd `reqUiRe` as The
 AMD-style modules via npm ?

npm has  a lo t o f w ea knes sesfor front-endu se ( installed layout is no t gre at , 
sho u ld  have  better su p p ort  f or  th e` ba seUrl  +moduleI D + '.js'sty le  of loading, si ngle fileJSinstalls), b utsome p eo ple wanta J S pac kage m a nagerand are
w il l ing to live wi t h  t hose  constraints. Ift ha t  is you, but s till w an t  t o aut hor 
in AMD st yl e mod u les tog et d y nam i c require([]) , better di r ect  sourc eusa g e andpower fu l  lo ader plugin  sup port in t he bro w ser, th e n thistool c anhel p.
# ## #amd ef i ne/ i nt erc e ptusage

J us trequi re i t i n  you r t op l evelapp module (f orexam p leindex .js,serv er .js): 

```j avasc ri pt
require('amd efin e/interce pt' ); 
`` `
Them oduledoe s n ot retu rn a va l ue,  s o n oneed to assign the  r e s ul t to a l ocal
v a ri ab l e.

Then  j ust  req u i re()code as  you nor mallyw ou ld  with N od e's re qu ire ().  Any. j s
lo aded a fter the  inte r cept require w i ll have the a m de f i ne chec k i njected inthe. j s so urce as  it is lo aded.  I t  d o es not modify the s ou rce on  disk , just
prepen ds some co n t e nt to th e te x to f the module a s itis loadedb y Node.
####  How amd efine/int e r cept wor ks
It  ov err i d es  the `Module. _ e xten si ons['.j s'] ` in No detoaut oma ti cally pre pend
the  a md ef in e s nippe t  above.So , i twil l aff e ct any .js f ilelo ad e d b y youra pp . 
##de fi ne()  us ag e

It  isb est  if you  use theano n ymou sfo rms ofdefine() in y ou r module:
` ``j avascr i p t
define (function (require) {
  var d epe ndenc y =require(' dep endenc y') ; 
});
` ``

or 

``` ja vas c r ipt
d e f in e([ 'd ependency' ] ,  fu nctio n(dep endency ) {

});
```

## R e qui reJS optimize r i nteg r a ti on. <a nam e= " opt i m izer"></name>
Version 1. 0. 3  o f the [Req u ire JS  optimi zer](ht tp:// r equirej s.org/doc s/optimiz at ion. h t ml) 
will have  support  for stri p pingt he  `if(ty peof d ef ine !== ' functi o n') ` che ck
men ti oned a bove,  s o you ca n include this snippetfor co de th atruns in t heb row ser, butavoi d taking t hecos t ofthe if()stat e me nto nce t he c o de is
opt i mi zed f or  deployment . ##Node0.4 Suppor t

I f you want to sup p ort Node 0.4,then a dd`re q uire `as the
 AMD-style_modules via_npm?

npm has a lot_of weaknesses_for_front-end use_(installed_layout is not_great,
should have better_support for the `baseUrl_+ moduleID +_'.js'_style of loading,
single file JS installs), but some people want a JS package manager_and_are
willing to_live_with_those constraints. If that is_you, but still want to_author
in AMD_style modules to get dynamic require([]), better direct_source_usage and
powerful loader_plugin support in the browser, then this tool can_help.

#### amdefine/intercept usage

Just require it in_your top level_app_module_(for example index.js, server.js):

```javascript
require('amdefine/intercept');
```

The_module does not return a value,_so no need to assign the_result to a local
variable.

Then just require() code_as you normally would with Node's_require(). Any.js
loaded after the intercept_require will_have the amdefine check injected_in
the.js source as_it is_loaded. It does_not modify the source on disk,_just
prepends some content_to the text of the module_as_it is loaded_by_Node.

####_How amdefine/intercept_works

It overrides the_`Module._extensions['.js']`_in Node_to_automatically prepend
the amdefine snippet above. So,_it_will affect any.js file loaded by your
app.

##_define() usage

It is best_if_you use the anonymous_forms of define() in your_module:

```javascript
define(function (require) {
   _var dependency_= require('dependency');
});
```

or

```javascript
define(['dependency'],_function (dependency) {

});
```

## RequireJS optimizer integration. <a name="optimizer"></name>

Version 1.0.3 of the_[RequireJS optimizer](http://requirejs.org/docs/optimization.html)
will have support for stripping_the `if (typeof define!==_'function')` check
mentioned_above,_so you can_include_this snippet_for code that runs in the
browser, but_avoid taking_the cost of the if() statement_once the code is
optimized_for_deployment.

## Node 0.4 Support

If you want_to support Node 0.4, then add_`require` as the