Bonnes Pratiques Web & Cloud
58.8K views | +4 today
Follow
Bonnes Pratiques Web & Cloud
Administration cloud et développement web
Curated by Mickael Ruau
Your new post is loading...
Your new post is loading...

Popular Tags

Current selected tag: 'gestionnaire de librairies'. Clear
Scooped by Mickael Ruau
Scoop.it!

Package management basics - Learn web development | MDN

Package management basics - Learn web development | MDN | Bonnes Pratiques Web & Cloud | Scoop.it
This brings us to the end of our tour of package managers. Our next move is to build up a sample toolchain, putting all that we've learnt so far into practice.

 

 

In this article we'll look at package managers in some detail to understand how we can use them in our own projects — to install project tool dependencies, keep them up-to-date, and more.

Mickael Ruau's insight:
 

What exactly is a package manager?

We've met npm already, but stepping back from npm itself, a package manager is a system that will manage your project dependencies.

The package manager will provide a method to install new dependencies (also referred to as "packages"), manage where packages are stored on your file system, and offer capabilities for you to publish your own packages.

In theory you may not need a package manager and you could manually download and store your project dependencies, but a package manager will seamlessly handle installing and uninstalling packages. If you didn't use one, you'd have to manually handle:

  • Finding all the correct package JavaScript files.
  • Checking them to make sure they don't have any known vulnerabilities.
  • Downloading them and putting them in the correct locations in your project.
  • Writing the code to include the package(s) in your application (this tends to be done using JavaScript modules, another subject that is worth reading up on and understanding).
  • Doing the same thing for all of the packages' sub-dependencies, of which there could be tens, or hundreds.
  • Removing all the files again if you want to remove the packages.

In addition, package managers handle duplicate dependencies (something that becomes important and common in front-end development).

In the case of npm (and JavaScript- and Node-based package managers) you have two options for where you install your dependencies. As we touched on in the previous article, dependencies can be installed globally or locally to your project. Although there tend to be more pros for installing globally, the pros for installing locally are more important — such as code portability and version locking.

For example, if your project relied on Webpack with a certain configuration, you'd want to ensure that if you installed that project on another machine or returned to it much later on, the configuration would still work. If a different version of Webpack was installed, it may not be compatible. To mitigate this dependencies are installed locally to a project.

To see local dependencies really shine, all you need to do is try to download and run an existing project — if it works and all the dependencies work right out of the box, then you have local dependencies to thank for the fact that the code is portable.

Note: npm is not the only package manager available. A successful and popular alternative package manager is Yarn. Yarn resolves the dependencies using a different algorithm that can mean a faster user experience. There are also a number of other emerging clients, such as pnpm.

Package registries

For a package manager to work, it needs to know where to install packages from, and this comes in the form of a package registry. The registry is a central place that a package is published to and thus can be installed from. npm, as well as being a package manager, is also the name of the most commonly-used package registry for JavaScript packages. The npm registry exists at npmjs.com.

npm is not the only option. You could manage your own package registry — products like Microsoft Azure allow you to create proxies to the npm registry (so you can override or lock certain packages), GitHub also offers a package registry service, and there will be likely more options appearing as time goes on.

What is important is that you ensure you've chosen the best registry for you. Many projects will use npm, and we’ll stick to this in our examples throughout the rest of the module.

Using the package ecosystem

Let’s run through an example to get you started with using a package manager and registry to install a command line utility.

Parcel is a(nother) tool that developers commonly use in their development process. Parcel is clever in that it can watch the contents of our code for calls to dependencies and automatically installs any dependencies it sees that our code needs. It can also automatically build our code.

In our previous chapter we installed Prettier as a global tool. Here however, let’s use npm to install Parcel as a local tool, as best practices dictate. We'll install it as part of an experimental app.

No comment yet.
Scooped by Mickael Ruau
Scoop.it!

SOAT Blog » Bower : un gestionnaire de dépendances pour le web

Bower est optimisé front-end et ne charge que le minimum (contrairement à npm, nous en reparlerons plus tard)

Mickael Ruau's insight:

D’abord c’est quoi un gestionnaire de dépendances ? C’est un outil qui gère les dépendances de votre projet (Captain Obvious à la rescousse), ce qui consiste principalement en l’installation, la désinstallation et la mise à jour de ces dépendances ; c’est un outil qui permet également la création d’un package (votre projet) qui pourra être distribué. Qu’est-ce qu’une dépendance en web ? Des fichiers JavaScript, CSS, HTML, etc.

Bower est donc un gestionnaire de packages, et plus précisément de dépendances web, créé par les équipes Twitter – d’où la référence oiselesque aux Bowerbirds –  avec entre autres contributeurs @fat (Bootstrap Twitter), James Burke (RequireJS), Paul Irish (spécialiste HTML5/CSS3 et évangélisateur de Google Chrome), Addy Osmani (Yeoman). Il permet de chercher, télécharger et installer les packages depuis leur dépôt (GitHub, SubVersion, URL, répertoire local, …) et de gérer leurs dépendances. Bower est optimisé pour le front-end, il utilise un arbre de dépendance plat ne nécessitant qu’une occurrence de chaque package et réduit ainsi le chargement de la page à son minimum.

No comment yet.
Scooped by Mickael Ruau
Scoop.it!

Améliorez votre processus de développement AngularJS avec Yeoman (1/2)

Améliorez votre processus de développement AngularJS avec Yeoman (1/2) | Bonnes Pratiques Web & Cloud | Scoop.it
Découvrez Yeoman appliqué à AngularJS pour gagner en productivité et éviter d'effectuer les mêmes actions, souvent simples, mais qui prennent du temps.
Mickael Ruau's insight:

Yeoman est un ensemble de trois outils utiles pour le développement Web en général : Yo, Grunt et Bower.

No comment yet.