How to pack the Javascript client library today?

I caught up with the modern client-side JS ecosystem and read about modular systems like CommonJS and AMD (including related tools - browser, requirejs, onejs, jam, dozens of others). If I am writing a Javascript library, how can I package it so that it can be most widely available (ideally, users who swear by CommonJS, AMD, and especially not)?

Popular libraries like jQuery seem to just use the old school file concatenation to create themselves and dynamically detect whether to write to export or global context. I am currently doing the same thing, but the main drawback is that if I (unlike jQuery) depend on several libraries, it is nice not to ask users to manually enable transitive dialing first. (Although I currently have only two dependencies.) And, of course, global pollution of the namespace.

Or maybe it's clean to generate multiple versions of my library for each context?

It also affects packaging and publication. There are several systems, but I believe that the main one is the gazebo, which is easy to handle, since all it does is sample. However, if I want to pack it for a component, then this requires the CommonJS module.

Are there other important aspects that I should be aware of? Are there any good project examples for all this?

+4
source share
1 answer

I thought about it myself, and I came to several conclusions:

  • Create one version of the framework that can be used for both global and AMD.
  • Do not think about asking your customers to manually enable dependencies, this is a uniprocessor action and should be performed in any case , regardless of whether you provide the package, (depending on the placement of third-party parties, anyway, this is what I say )
  • I use Grunt to create a project / packaging / testing / casting / whatever, so for all other packaging alternatives I have different tasks.

So, in a word, first create a package for the "new age" for the "old school / AMD".

PS

I am also strongly convinced that your packaging and delivery / needs process should not (when possible) dictate your architectural and development decisions .

I try to build the most customizable, modular and useful code that I can, using the packaging paradigm of my choice, then I consider alternative packaging. If I succeeded in the first part, the second, as a rule, is either straightforward or requires very few changes in the database (due to modularity and the correct principles of application at the first stage).

+3
source

Source: https://habr.com/ru/post/1481498/


All Articles