Hey Yuri,
I think it would help knowing a concrete use case to help you figure out a reasonable solution. Daniel has provided excellent advice, but the best course of action depends more concretely on the exact situation to solve.
As Daniel mentioned, simplest way is write common.js for all your code.
From node you can use the files however you require, and for the browser
you'll have to set up a couple of scripts in package.json to compile (browserify & watchify most probably from what I hear).
As Daniel mentioned, the tradeoff is that your browser bundle may have dependencies that could be shared with the page. For that browserify's exclude should help ( https://github.com/substack/browserify-handbook#excluding) not bundling the same libraries twice.
Regarding code structure, one way I've seen work is keeping the environment agnostic code in lib/shared/ or lib/common/, and then having lib/server/ and lib/client with node & browser code respectively.
If you keep an npm library in development separately from your project, then just npm link it and you'll be able to develop for the npm library and the app without having to install continuously and things like that ( https://docs.npmjs.com/cli/link ).
Cheers.
On Sun, Dec 20, 2015 at 10:31 AM, Santhosh Thottingal < santhosh.thottingal@gmail.com> wrote:
I had used returnExports pattern defined in https://github.com/umdjs/umd to get a module that works in Node, AMD and browser globals. That repo has several patterns and tools for this and you may find useful to solve your usecase.
Thanks Santhosh _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l