What is "modular" a project?

0

I am learning about Frontend technologies and I am learning how to use Browserify and I have been using the '' modular '' definition with Browserify. I hope someone can tell me what modular means and what it is for. Thanks in advance.

    
asked by Ricardo A 21.02.2017 в 01:03
source

1 answer

3

This is a pretty abstract question and there is no precise answer in the global javascript scenario. What is or is not a module has at least three interpretations (three and a half counting UMD) but I will answer you in a general plan.

When you use a JS library, it may have requirements or dependencies. For example, when you use bootstrap, it depends on jQuery, so the best thing to do is to put the jquery script tag before the bootstrap script tag.

Those dependencies can have a very elaborate nesting level, such that it can not be solved merely by ordering the script tags. It can be given for example that

- Datatables Bootstrap depende de
  - DataTables que depende de
    - jQuery
  - Bootstrap que depende de
    - jQuery

That dependency tree is trivial to solve in Node.js, because everything is in your local system and you load it when you mount the application. In the browser, however, you have to choose between:

  • require a million scripts with no real control over the dependency hierarchy
  • use an asynchronous system such as Require.js or SystemJS and load the dependencies as they are required (with the latency that carries)
  • concatenate in a module the entry points of the libraries you need.

Browserify complies with the third option. Concatenate in a single file all the dependencies of what you want to use, knowing only the last section. Since the library you want to use declare its dependencies

var DataTables=require('DataTables');

And its dependencies declare their dependencies, and so on, browserify is responsible for building a module that includes all the nested requirements of the final library that you want to use.

Browserify jumped to fame about 5 years ago and is still ultra popular, but today there are other libraries (Webpack, JSPM) that do a similar job solving the but of browserify that is that two libraries browserificadas can have a common dependency (for example jQuery) and in each one comes jQuery as a gift, attached.

    
answered by 21.02.2017 / 02:24
source