Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Minifying Angular apps with Gulp
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Adil" data-source="post: 339096" data-attributes="member: 3031"><p>[CODE]</p><p>// Compile source via closure</p><p>gulp.task('compile', function () {</p><p> gulp.src('static/js/app.min.js')</p><p> .pipe(closureCompiler({</p><p> compilerPath: 'third_party/compiler.jar',</p><p> fileName: 'app.dist.js',</p><p> compilation_level: 'ADVANCED_OPTIMIZATIONS', //this removes all dud code and renames variables aggressively</p><p> compilerFlags: {</p><p> externs : [</p><p> 'third_party/angular_extern.js', 'third_party/oauth2_extern.js' //externs for compilation</p><p> ]</p><p> }</p><p> })).pipe(gulp.dest('static/js/'));</p><p>});</p><p></p><p></p><p>// Concatenate angular app into one file</p><p>gulp.task('concat', function() {</p><p> return gulp.src('static/js/app/**/*.js').</p><p> pipe(concat('app.min.js'))</p><p> .pipe(gulp.dest('static/js'));</p><p>});</p><p></p><p></p><p>// Minify via ngmin - so closure is able to correctly compile the code</p><p>gulp.task('ngmin', function() {</p><p> return gulp.src('static/js/app.min.js')</p><p> .pipe(ngmin())</p><p> .pipe(gulp.dest('static/js/'));</p><p>});</p><p></p><p></p><p>/*</p><p> TODO</p><p> JSHint</p><p> AppEngine deployment (write own plugin for this)</p><p> Better css minification</p><p> Angular unit tests</p><p>*/</p><p>// run all js tasks with a message at the end</p><p>gulp.task('minjs', function() {</p><p> runSequence('concat', 'ngmin', 'compile', function() {</p><p> console.log('Compiled JavaScript via Angular.JS');</p><p> });</p><p>});</p><p>[/CODE]</p><p></p><p>It basically concatenates all my angular files, minifies them via ngmin, and then compiles them via closure (which is a pretty aggressive js compiler). This results in 328 lines (including whitespace) being trimmed down to 12.. which is pretty awesome!</p><p></p><p>(Links that you may find interesting)</p><p>ngmin: <a href="https://github.com/btford/ngmin" target="_blank">https://github.com/btford/ngmin</a></p><p>Closure Compiler: <a href="https://github.com/google/closure-compiler" target="_blank">https://github.com/google/closure-compiler</a></p><p>Gulp.js: <a href="http://gulpjs.com/" target="_blank">http://gulpjs.com/</a></p></blockquote><p></p>
[QUOTE="Adil, post: 339096, member: 3031"] [CODE] // Compile source via closure gulp.task('compile', function () { gulp.src('static/js/app.min.js') .pipe(closureCompiler({ compilerPath: 'third_party/compiler.jar', fileName: 'app.dist.js', compilation_level: 'ADVANCED_OPTIMIZATIONS', //this removes all dud code and renames variables aggressively compilerFlags: { externs : [ 'third_party/angular_extern.js', 'third_party/oauth2_extern.js' //externs for compilation ] } })).pipe(gulp.dest('static/js/')); }); // Concatenate angular app into one file gulp.task('concat', function() { return gulp.src('static/js/app/**/*.js'). pipe(concat('app.min.js')) .pipe(gulp.dest('static/js')); }); // Minify via ngmin - so closure is able to correctly compile the code gulp.task('ngmin', function() { return gulp.src('static/js/app.min.js') .pipe(ngmin()) .pipe(gulp.dest('static/js/')); }); /* TODO JSHint AppEngine deployment (write own plugin for this) Better css minification Angular unit tests */ // run all js tasks with a message at the end gulp.task('minjs', function() { runSequence('concat', 'ngmin', 'compile', function() { console.log('Compiled JavaScript via Angular.JS'); }); }); [/CODE] It basically concatenates all my angular files, minifies them via ngmin, and then compiles them via closure (which is a pretty aggressive js compiler). This results in 328 lines (including whitespace) being trimmed down to 12.. which is pretty awesome! (Links that you may find interesting) ngmin: [URL]https://github.com/btford/ngmin[/URL] Closure Compiler: [URL]https://github.com/google/closure-compiler[/URL] Gulp.js: [URL]http://gulpjs.com/[/URL] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Minifying Angular apps with Gulp
Top