<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Google Closure Compiler &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/google-closure-compiler/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 16:51:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Google Closure Compiler &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Combining and Minifying JavaScript Files with Google Closure Compiler</title>
		<link>https://myshittycode.com/2014/10/20/combining-and-minifying-javascript-files-with-google-closure-compiler/</link>
					<comments>https://myshittycode.com/2014/10/20/combining-and-minifying-javascript-files-with-google-closure-compiler/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Mon, 20 Oct 2014 19:10:46 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Google Closure Compiler]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=589</guid>

					<description><![CDATA[<p>GOAL The goal is to combine and minify several JS files into one JS file in the right order. PROBLEM Let&#8217;s assume we have the following directory structure with three JS files. Directory Structure appdev.js appdev.blackcow.js appdev.whitesheep.js SOLUTION To pull this off, we will leverage Google Closure Compiler. There are multiple ways to use this [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/10/20/combining-and-minifying-javascript-files-with-google-closure-compiler/">Combining and Minifying JavaScript Files with Google Closure Compiler</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">GOAL</h2>



<p>The goal is to combine and minify several JS files into one JS file in the right order.</p>



<h2 class="wp-block-heading">PROBLEM</h2>



<p>Let&#8217;s assume we have the following directory structure with three JS files.</p>



<h3 class="wp-block-heading">Directory Structure</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
appdev
└── src
    ├── appdev.blackcow.js
    ├── appdev.js
    └── appdev.whitesheep.js
</pre></div>


<h3 class="wp-block-heading">appdev.js</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
var AppDev = {
    modules : &#x5B;],

    start : function () {
        var moduleName;
        for ( moduleName in AppDev.modules ) {
            if ( AppDev.modules.hasOwnProperty( moduleName ) ) {
                AppDev.modules&#x5B;moduleName]();
            }
        }
    }
};
</pre></div>


<h3 class="wp-block-heading">appdev.blackcow.js</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
AppDev.modules.blackcow = function ( config ) {
    console.log( &#039;in black cow module...&#039;, config );
};
</pre></div>


<h3 class="wp-block-heading">appdev.whitesheep.js</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
AppDev.modules.whitesheep = function ( config ) {
    console.log( &#039;in white sheep module...&#039;, config );
};
</pre></div>


<h2 class="wp-block-heading">SOLUTION</h2>



<p>To pull this off, we will leverage <a href="https://developers.google.com/closure/compiler/" target="_blank" rel="noopener">Google Closure Compiler</a>.</p>



<p>There are multiple ways to use this compiler, but if you are using Mac, the easiest approach, in my opinion, is to install this compiler using <a href="http://brew.sh/" target="_blank" rel="noopener">Brew</a>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
brew install closure-compiler
</pre></div>


<p>Once installed, navigate to the <b>appdev</b> directory and run the following command:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
closure-compiler --js `find src/**/*.js` --js_output_file appdev.min.js
</pre></div>


<p>Now, a new file called <b>appdev.min.js</b> will be created.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; highlight: [2]; title: ; notranslate">
appdev
├── appdev.min.js
└── src
    ├── appdev.blackcow.js
    ├── appdev.js
    └── appdev.whitesheep.js
</pre></div>


<p>The reformatted file content looks like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
AppDev.modules.blackcow = function ( a ) {
    console.log( &quot;in black cow module...&quot;, a )
};
var AppDev = {
    modules : &#x5B;], start : function () {
        for ( var a in AppDev.modules ) {
            if ( AppDev.modules.hasOwnProperty( a ) ) {
                AppDev.modules&#x5B;a]()
            }
        }
    }
};
AppDev.modules.whitesheep = function ( a ) {
    console.log( &quot;in white sheep module...&quot;, a )
};
</pre></div>


<p>The generated code is going to cause problem because the Closure Compiler basically appends each file content based on the order of the JS file names.</p>



<p>To fix this, we have to specify the dependencies so that the Closure Compiler will auto-sort the files correctly.</p>



<h3 class="wp-block-heading">appdev.js</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; highlight: [1]; title: ; notranslate">
goog.provide(&#039;AppDev&#039;);

var AppDev = {
    modules : &#x5B;],

    start : function () {
        var moduleName;
        for ( moduleName in AppDev.modules ) {
            if ( AppDev.modules.hasOwnProperty( moduleName ) ) {
                AppDev.modules&#x5B;moduleName]();
            }
        }
    }
};
</pre></div>


<h3 class="wp-block-heading">appdev.blackcow.js</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; highlight: [1]; title: ; notranslate">
goog.require(&#039;AppDev&#039;);

AppDev.modules.blackcow = function ( config ) {
    console.log( &#039;in black cow module...&#039;, config );
};
</pre></div>


<h3 class="wp-block-heading">appdev.whitesheep.js</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; highlight: [1]; title: ; notranslate">
goog.require(&#039;AppDev&#039;);

AppDev.modules.whitesheep = function ( config ) {
    console.log( &#039;in white sheep module...&#039;, config );
};
</pre></div>


<p>After rerunning the compiler, the file content for <b>appdev.min.js</b> now looks correct.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
var AppDev = {
    modules : &#x5B;], start : function () {
        for ( var a in AppDev.modules ) {
            if ( AppDev.modules.hasOwnProperty( a ) ) {
                AppDev.modules&#x5B;a]()
            }
        }
    }
};
AppDev.modules.blackcow = function ( a ) {
    console.log( &quot;in black cow module...&quot;, a )
};
AppDev.modules.whitesheep = function ( a ) {
    console.log( &quot;in white sheep module...&quot;, a )
};
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2014/10/20/combining-and-minifying-javascript-files-with-google-closure-compiler/">Combining and Minifying JavaScript Files with Google Closure Compiler</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2014/10/20/combining-and-minifying-javascript-files-with-google-closure-compiler/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">589</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching 56/67 queries in 0.017 seconds using Disk

Served from: myshittycode.com @ 2026-02-18 18:09:56 by W3 Total Cache
-->