The Holy Grail - Gulp + Sass + LiveReload + Foundation
To have a gulp workflow that with a single process,
public/If you have not have npm, gulp, or bower, you need to install them.
to install npm
brew install npm
to install gulp
npm install -g gulp
to install bower
npm install -g bower
initialize your project with a package.json file
npm init
setup your .gitignore file to ignore node_modules
echo "node_modules" >> .gitignore
add and commit your 2 new files to be tracked in git
install and save required dependencies using npm install -D [node_module name]
gulpgulp-sassgulp-connectsetup sass source directory mkdir sass/
setup sass source file touch sass/styles.scss
setup sass compiled output directory mkdir -p public/css
setup root html5 template file touch public/index.html
generate a base html5 template in public/index.html
include a link to css/styles.css
include an h1 element in the body with the content of Hello Gulp, Sass, and Livereload
setup a Gulpfile touch gulpfile.js
setup the Gulpfile tasks,
subl gulpfile.jstest gulp task
subl sass/styles.scss$dark-color : #333333;
body {
background: $dark-color;
}
gulp in your terminalls public/css (should say styles.css)cat public/css/styles.css ( should be proper css )test livereload
open localhost:8080styles.scssh1 {
color: #F1F1F1;
}
once gulp sass and livereload are wired up correctly, commit your new files
make sure to keep your "gulp" terminal running and visible, if your sass source is invalid, it will crash the watching gulp process, and you will want to see the error message that will output in that terminal. Then you can restart your gulp watcher after fixing your errors.
After adding new files to your public/ directory (like images or javascript), you may need to kill then restart your gulp task
initialize bower config bower init
say yes to all
create a new .bowerrc file subl .bowerrc and add the following 3 lines to this file
{
"directory" : "public/bower_components"
}
install foundation, bower install -S foundation
add public/bower_components to you .gitignore file
echo "public/bower_components" >> .gitignore
create a sass partial subdirectory mkdir sass/partials
copy over the foundatian settings partial, into your sass/partials directory
cp public/bower_components/foundation/scss/foundation/_settings.scss sass/partials/
create a new partial named _foundation.scss in the sass/partials/ directory
subl sass/partials/_foundation.scss
import any modules that you need, into the _foundations.scss partial, this file will only contain the modules you need to use. refer to the foundation documentation to choose which components you need for your layout. if you want to use the topbar, rtfm on how to use it here http://foundation.zurb.com/docs/components/topbar.html. import each model you need, for example:
@import "../public/bower_components/foundation/scss/foundation/components/grid";
@import "../public/bower_components/foundation/scss/foundation/components/block-grid";
@import "../public/bower_components/foundation/scss/foundation/components/clearing";
@import "../public/bower_components/foundation/scss/foundation/components/top-bar";
@import "../public/bower_components/foundation/scss/foundation/components/type";
@import "../public/bower_components/foundation/scss/foundation/components/visibility";
notice that we updated our paths to the proper partial file locations installed by bower
fix the path in our other partial, _settings.scss, on line 58
// change this
@import "foundation/functions";
// to this
@import "../public/bower_components/foundation/scss/foundation/functions";
import your 2 partials into your main styles.scss file:
at the top
@import "partials/settings";
@import "partials/foundation";
test that foundation is being properly loaded, it should have autocompiled (sass) if your gulp watcher was on, if not, (stop and) restart it.
public/css/styles.csssass/partials/_foundation.scss), it will be like 1000 to 3000 lines of compiled css.In order for the webpage to render and scale properly on mobile devices, add this meta tag to your public/index.html file in the the <head> element
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
To take advantage of feature detection, include the modernizr plugin,
add this script tag to your public/index.html file at the end of the <body> element, before any of your javascript files
<script src="/bower_components/modernizr/modernizr.js"></script>
Include the required jquery and foundation javascript libraries (right after the modernizr include)
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/bower_components/foundation/js/foundation.min.js"></script>
<script>
$(document).foundation();
</script>