Node.js require() vs RequireJS?

前端 未结 3 874
北海茫月
北海茫月 2021-02-04 19:38

Hello with RequireJS I can set a base path like this: base : \'./app/\' so when I am in ./app/foo/bar/ for example and I have a script where I use

相关标签:
3条回答
  • 2021-02-04 19:46

    Use uRequire which provides a 'bridge' between nodejs require and AMD define modules, without reinventing the wheel (it is build on top of the two standards). It basically converts modules from AMD or commonJS format to the other format or UMD that runs smoothly on both nodejs & the browser.

    It is also translating dependency paths with flexible path conventions, so you can have either '../../foo' or 'bar/foo' depending on which makes more sense at the point you are at.

    Your AMD or UMD modules are loaded asynchronously on browser (using AMD/requireJs or other AMD loader) and on node the asynchronous require(['dep1', 'dep2'], function(dep1,dep2){...}) is also simulated.

    0 讨论(0)
  • 2021-02-04 20:00
    --alias, -a    Register an alias with a colon separator: "to:from"
                 Example: --alias 'jquery:jquery-browserify'   
    

    You can register aliases with browserify, so that covers your renaming.

    As for your rooted absolute paths, that can't really be done. As mentioned modul8 has a namespacing mechanism to solve this.

    I would recommend you pong SubStack in #stackvm on freenode and ask him directly.

    0 讨论(0)
  • 2021-02-04 20:06

    It may or may not help you, but I believe the Dojo Frameworks AMD Loader is API compatible with RequireJS and providing you are using a new microkernel does not pollute the global namespace.

    I believe it only has require() and define() in the global namespace now.

    Anyway their method of dealing with this is to do something like:

    require(["dojo/node!util"], function(util){
        // Module available as util
    });
    

    The documentation is at http://dojotoolkit.org/reference-guide/1.8/dojo/node.html

    0 讨论(0)
提交回复
热议问题