Node.js require() vs RequireJS?

前端 未结 3 893
北海茫月
北海茫月 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.

提交回复
热议问题