node.js - How to write modules that are both nodejs compatible and browser compatible? -


i writing node module {collection of modules}and in future might ported browser environments too. reason looking programming techniques allow me write code once , reuse same, may if requires kind of running build , fine.

its fine if workflow,

  • write node modules
  • run build script converts above written code single js file able run in browser enviroments

please not suggest me browserify.

why no browserfiy or other similar stuff? saw code generated . huge , had lot of browserify introduced code. found difficult troubleshoot , go through code have written

i recommend giving @ browserify. other that, add universal module definition (umdjs) exporter in files. allow expose modules in node, browserify, requirejs/amd, or thrown script tag on site.

can use module transpiler -- write in a es6 module exporter, , have convert use in browser, or commonjs/node environment.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -