What are your thoughts on the JavaScript dependency management proposal

I recently did a lot of JavaScript programming in the context of developing Rich Internet Application . My opinion at the beginning of development is pretty much what it is now; JS RIA works, but no development tools.

One of the tools that I missed, in particular, was dependency management. I found that I had a lot of HTML pages declaring all their dependencies on JS files, and it became difficult to maintain.

What I would like to know is your thoughts on the project I started: Maven JavaScript Import. I intend to eventually release the project as an open source, but at the moment I was just messing with it (a lot has already been developed, though).

Dependency declaration

My thoughts are based on using Maven to declare JS files as dependencies. This is how I declared jQuery project dependency in my pom file:

<dependency>
  <groupId>com.jquery</groupId>
  <artifactId>jquery</artifactId>
  <version>1.4.2</version>
  <type>js</type>
</dependency>

The file, which then depends on jQuery, has two methods for declaring its dependency:

  • via the @import operator in the comment block; or
  • just declare the required global variable.

Import

Explicit imports take the form:

/**
 * @import com.jquery:jquery
 */

As you can see, the import format <groupId>:<artifactId>. The approach has the advantage that there is no file / version information in the js file, which has a dependency. These GAV options allow artifacts declared in the POM file.

Global wars

Instead of the above @import, if the dependent file declares variables in the global scope, then simply declaring any of these global characters is all that is required. For example, if the file requires jQuery:

var $;

... $, , jQuery.

@import, , , ( JSLint !).

HTML , JS, , , . Maven JS ( ) . HTML , , script , , . Maven, , . .

? -, JS RIA?

+3
2

, JavaScript . , HTML js , . HTML script ?

, https://github.com/ProggerPete/JavaScript-Tools. .

+1

, Bower - .js.

0

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


All Articles