requirejs / almond

A minimal AMD API implementation for use after optimized builds
Other
2.42k stars 168 forks source link

Almond + Electron #119

Closed paul-piro closed 8 years ago

paul-piro commented 8 years ago

Almond JS doesn't work with Electron apps, the library is overriding the NodeJS require function and the app cannot include native modules like require('electron')

Can we rename the require function from Almond to requirejs ?

jrburke commented 8 years ago

You could wrap the code that uses almond in a closure so that the require/requirejs/define variables it uses are just usable inside that closure. If using the r.js optimizer to build the almond bundle, the wrap or wrap.start/end or wrap.startFile/endFile build options can help with that.

Closing as a discussion ticket, but feel free to continue discussion here.

paul-piro commented 8 years ago

I'm using grunt task to build production js. Could you give me some example how to use this closure?

Thank you

jrburke commented 8 years ago

It depends on the kind of grunt task that is being used, but basically, if you are not using r.js to generate the bundle, you can prepend a (function(){ and append }()); to the generated file, that would be the same result as the wrap config.

paul-piro commented 8 years ago

I'm using grunt-contrib-requirejs task which i guess is using r.js to generate the bundle, so can i use Almond JS?

On Tue, Aug 16, 2016 at 5:05 AM, James Burke notifications@github.com wrote:

It depends on the kind of grunt task that is being used, but basically, if you are not using r.js to generate the bundle, you can prepend a (function(){ and append }()); to the generated file, that would be the same result as the wrap config.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/requirejs/almond/issues/119#issuecomment-239982385, or mute the thread https://github.com/notifications/unsubscribe-auth/AAh57l4UH2lKH0sj-PL8z2jUeZtYnXWSks5qgRrygaJpZM4JjIG7 .

jrburke commented 8 years ago

I'm not very familiar with the grunt task, but I believe it allows passing the same config properties that r.js uses through it, so it should be able to use the wrap config properties mentioned above.