Every developer, who cares about his time, must have his own tiny scaffold on his GitHub-repo just for himself, just to start new project by “git clone” in terminal, just to minimize spent time on making file’s structure, setting up dependencies, minimizing images, compiling Less/Sass etc. Because, developers are really lazy people and we shouldn’t be ashamed of it.
So, today I wanna tell you a bit about my GitHub-repo for this stuff.
Here we go:
https://github.com/greenxiii/Galpus/
First of all, I will start with dependencies. I love to use Bower(http://bower.io/) for this. It’s really easy, and it works good as we need. Just write a list of libs that you need and bower will install other dependencies for this libs and will install it into bower_components folder. Also, if you don’t like that folder name as I do, you have to create settings file for bower, named “.bowerrc”. I really like if my dependencies are located in “lib” folder, so in repo you can see those lines in .bowerrc file:
{
“directory”: “lib/”
}
That’s so cool and easy, isn’t it?
Ok, now let’s talk a bit about my favorite part of my working process. I love to code with great cool instruments like CoffeeScript for JS, Less with SMACSS for styles, Karma with Jasmine for testing js-code, and, of course we had better minimize and uglify all these files with images for production. Besides, that would be amazing if we add BrowserSync to all these files. But wait, just think of setting up all of these together, doesn’t it scare you? It’s really boring and routine, especially, if you need to do this every day or week. That’s why my repo is saving my lazy life.
However, what should I do to kill that routine?
Of course I use Gulp!
If you don’t know, I’m inveterate Gulp-lover.
Did you say “CoffeeScript”? – Easy, “npm install gulp-coffee”.
Did you say “Less”? – Easy, “npm install gulp-less”
Did you say “minimize images”? – Easy!
Did you say “uglify js and minimize styles”? – Easy! Easy!
Karma and Jasmine? – Easy!
BrowserSync? – Easy and amazing!
So, in my repo I have all those tasks.
If you look at file structure, you will see that CoffeeScript will be compiled from “coffee” folder into “js” folder and, then js from js folder will be uglified into js/min folder. It the same way styles from “less” folder will be compiled into “css” folder and then from “css” folder it will be minimized to “css/min” folder.
Js tests will be started from “spec” folder.
Also, images will be compressed from “images” folder to “images/compressed” folder. Easy, isn’t it?
And, of course let’s talk a bit about BrowserSync. I won’t write much information about it, because I can write big text blocks about all of used before packages and that will be really hard to read.
Also, because our website hasn’t been adapted for BigData 🙂
So, what do you need to know? First of all, BrowserSync creates a small server, but if you already have a server setup, BrowserSync can hook into that server and act as a proxy. From the box you will have set up BrowserSync just to load it from folder, already have another server setup, you should rewrite this code in gulpfile.js:
gulp.task(‘browser-sync’, [‘coffee-compile’, ‘styles-compile’], function() {
bs.init({
server: {
baseDir: “./”
}
// proxy: “yourwebsite.com”
});
});
to this:
gulp.task(‘browser-sync’, [‘coffee-compile’, ‘styles-compile’], function() {
bs.init({
proxy: “yourwebsite.com”
});
});
So, that’s all what you need to start good and extendable project. That’s really easy for beginners and that’s really quick for pros.
I know that my repo have to be improved and of course that will be done! In plans I will set up e2e tests with Karma and will add Jade or Haml preprocessor for html.
For now, you can use it as I do it now.