P E N C I L
Login

Requirejs

  1. http://requirejs.org/docs/api.html
    1. Important in doc: "Other module notes"
  2. https://www.safaribooksonline.com/blog/2013/10/01/configuring-requirejs-for-fun-and-profit
  3. Relative
    1. https://www.safaribooksonline.com/blog/2013/10/01/configuring-requirejs-for-fun-and-profit
    2. http://requirejs.org/docs/api.html#config-paths
    3. define(['mypath/mymodule'])
      1. baseUrl: '/base', paths: { mypath: './path'}
        => /base/path/mymodule
      2. baseUrl: '/base', paths: { mypath: '/path'}
        => /path/mymodule
  4. Relative
    1. define(['./myfolder', './../my'], function())
      1. define(['./myfolder'], function())
        => relative to current JS file (Note: there must be ./  and no .js)
        NOTE: even if we go to parent, we still need './..'
      2. define(['/absolute'  or 'my.js' or 'http://], function())
        => resolve to relativly to current HTML file (not js file)
      3. define(['my'], function())
        => module baseUrl+'my' +'.js'
        => or paths if 
      4. INCORRECT use (unpredictable result)
        define([./my.js])  => the based url is not resolve  
        define([../toparent])  => the based url is not resolve , we need to use ./..
    2. Global require('./my', function()) 
      Global require: use just one to boot strap the whole app does not have 'relative' concent
      './my' == 'my' and it's resolved with baseUrl
      1. Hint: global require: use absolute (/... or .js) or path resolve (my/main.js) . Other define can use relative to module
    3. baseUrl: if not definedi n config, it's the path of data-main. If there is no data-main then it's the page url
  5. Configure
    1. require={}... before loading requirejs 
      or load afte that require.config={}
    2.