Organize and merge JS files, Google Closure?

I am trying to combine all my plugins to change this:

<html>
    <head>
    </head>
    <body>    
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="js/plugin1.js"></script>
        <script src="js/plugin2.js"></script>
        <script src="js/plugin3.js"></script>
        <script src="js/plugin4.js"></script>
    </body>
</html>

:

<html>
    <head>
    </head>
    <body>    
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="js/plugins.min.js"></script>
    </body>
</html>

The main idea is to have a tool to automatically import into my plugins.js file for all the plugins that I need for my websites, as well as to minimize them when compiling. I tested using Google Closure (a downloadable Java version of the compiler), and I decided how to minimize the files, but I cannot import external files. So I would like to ask you if you can tell me if Google Closure is the tool I'm looking for, or if I should use another tool or method.

With "auto import", I mean something like:

PLUGINS / HELLO.JS

function hello(name) {
    alert('Hello, ' + name);
}

PLUGINS.JS

@import hello.js
hello('New user');

I hope I made it clear, I apologize if I ruined my English.

Thank!!

+5
4

. -js:

java -jar compiler.jar --js 1.js --js 2.js --js 3.js --js_output_file all.js

( Closure Compiler):

// ==ClosureCompiler==
// @code_url 1.js
// @code_url 2.js
// @code_url 3.js
// ==/ClosureCompiler==

... "main.js" - .: (

+5

Closure-compiler , , Closure-library - goog.require. jQuery , , , .

, , .

Note. This is not expected to be an accepted answer to the question. The question was asked specifically about the Closure compiler, and I wanted to make sure that at least somewhere it was indicated that the compiler would not work as it wished.

+1
source

You might want to take a look at require.js

0
source

All Articles