node.js - Using Browserify with JQuery - what does it 'really' mean? -


new javascript, etc. wanted pure html/javascript project. looked @ requirejs, , read, seemed me few projects went through pain of switching requirejs project node/browserify projects.

so thought start node/browserify project.

my limited understanding when browserify project, packages dependencies along javascript.

couple of questions

  1. does create 1 file?

  2. if creates multiple files, happens if multiple files depend on same project (such lodash)? append source code of required project multiple times?

  3. what if i'm using browser side library such jquery...in scenario, according docs, seems need use jsdom. happens when browserify this? more expensive using jquery?

node.js , jquery:

one important distinction between node.js , browser node.js just a:

platform built on chrome's javascript runtime

it means allows execute javascript code. browsers have own js runtime execute scripts on client side and in addition provide mean "for representing , interacting objects in html, xhtml, , xml documents." , document object model (dom).

in node.js there no html files , have js code, using jquery in node.js doesn't make sense, since jquery:

makes things html document traversal , manipulation, event handling, animation, , ajax simpler easy-to-use api works across multitude of browsers.


node.js , browserify:

node.js provides module loading system allows include other modules using require keyword. js code containing require code cannot executed in browser, since ecma5 there no built-in module loading mechanisms.

browserify mocks require keyword , allows make use of in browsers, explained here:

browserify uses term entry file(s) describe start reading dependency graph, , output referred bundle.


node.js project?:

since project aimed run inside browser (and not on server) there no need migrate node.js. however, use nodejs better maintain project:

  • seperate project in modules in development , create single bundle file browserify production.
  • use number of preprocessors, , compiles (e.g. coffeescript, less, etc)
  • test modules (e.g mocha, jest)
  • use build system (e.g gulp)
  • etc...

and after have, tested modules (and compiled coffeescript!) let browserify created main.bundle.js , import in production:

<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="main.bundle.js"></script> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -