6

I'm currently writing a web app that I later intend to deploy using node-webkit. I want to use as little node.js as possible so that I have the option to easily deploy to the web without having to rewrite large portions of the code.

I'm using Jam.js as a package manager. Obviously there is the issue of node.js's require conflicting with require.js's require. Using requirejs instead of require seems to be a great option. However, Jam.js compiles the require.config.js-file and uses require (instead of requirejs) inside of it.

Currently, I have to do window.require = undefined; to make Jam.js's require.js work in node-webkit.

Is there a way to make Jam.js compile the require.config.js-file using requirejs instead of require?

Or is there a different solution that lets me use both Jam.js and node.js's require without having to do something like window.require = undefined;? I find the solution presented in the node-webkit FAQ not very satisfying.

Thanks for your help!

Macks
  • 1,696
  • 5
  • 23
  • 38

1 Answers1

3

These links might help you with your issue:

http://requirejs.org/docs/node.html

http://durandaljs.com/documentation/Native-Apps-With-Node-Webkit.html

https://github.com/caolan/jam

jamesmortensen
  • 33,636
  • 11
  • 99
  • 120
JFelton
  • 532
  • 5
  • 16
  • [This](http://durandaljs.com/documentation/Native-Apps-With-Node-Webkit/) might do the trick. Thanks! – Macks Oct 21 '13 at 14:54
  • @Macks and JFelton, your durandljs.com link is broken. Is it possible we can update that to a working one, assuming the content exists somewhere else? – jamesmortensen May 02 '14 at 20:57
  • 1
    @jmort253 I'm not sure how to update my comment, but this seems to be the new URL to the article: http://durandaljs.com/documentation/Native-Apps-With-Node-Webkit.html If I could go back in time, I would have written my app using CommonJS modules. That would work perfectly with node/node-webkit and I could easily compile them for the web with Browserify. – Macks May 03 '14 at 00:47
  • @Macks - Thanks for the link! I was wondering about require. About your CommonJS comment, are you saying that you wouldn't use either of these solutions now that you've dug in a bit? – jamesmortensen May 03 '14 at 00:50
  • @jmort253 no problem! Yeah, if I was making a node-webkit app now, I would just use node's module-system. If I decided to port it to the browser/web later on, I could use Browserify (which I personally would use for browser/web apps either way). – Macks May 03 '14 at 01:46
  • @Macks - Interesting... I was under the impression wrapping things in modules would actually tie me to the Node/node-webkit platform, so I'm starting by just using script tags, which should also be compatible with both the web as well as node-webkit, unless I'm missing something? – jamesmortensen May 03 '14 at 01:47
  • 1
    @jmort253 Wrapping things in modules does not tie you to node, because you can use Browserify to compile your modularized project to web. Browserify seems to be the new way to go in front-end web development anyways, so definitely check it out if you haven't yet. Using script-tags comes with many issues like http-requests, global variables, namespacing, manually inserting these tags in correct order, having to concat/minify them explicitly for production, etc. Using script-tags also ties you to **web** – you can't use those script-files in node if you're using global variables. – Macks May 03 '14 at 13:15
  • This is the link that solved it all for me http://durandaljs.com/documentation/Native-Apps-With-Node-Webkit.html – StackHola Jan 30 '15 at 12:53