Set up a boilerplate Gulp + Scss + LiveReload + Foundation 5 workflow that:
- watches for any scss changes, then compiles scss source into css
- watches for any changes in the public directory, triggers live-reload
- serves your static content in
public/
If you do not have npm, gulp, or bower on your computer you need to install them. If you already have installed these, you do not need to run these commands.
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
filenpm init
-
Install and save required dependencies:
npm install -D gulp
npm install -D gulp-sass
npm install -D gulp-connect
Contents of gulpfile:
var gulp = require('gulp');
var sass = require('gulp-sass');
var connect = require('gulp-connect');
gulp.task('connect', function(){
connect.server({
root: 'public',
livereload: true
});
});
gulp.task('sass', function () {
return gulp.src('./sass/*.scss')
.pipe(sass({
errLogToConsole: true,
sourceComments: true,
includePaths: ['bower_components/foundation/scss']
}).on('error', sass.logError))
.pipe(gulp.dest('./public/css'));
});
gulp.task('livereload', function (){
gulp.src('./public/**/*')
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch('./sass/**/*.scss', ['sass']);
gulp.watch('./public/**/*', ['livereload']);
});
gulp.task('default', ['connect', 'watch', 'sass']);
- Set up a
sass
directory in your root directory. This directory should contain:styles.scss
partials
directory
- Set up a
public
directory in your root directory. This directory should contain:index.html
js
directorycss
directory
- generate a base html5 template
- include a link that loads
/css/styles.css
- include an
h1
with some text.
- Write the 'hello world' of scss in the
styles.scss
file.$bright : #FF0000; body { background: $bright; }
- Run
gulp
in your terminal - Check
localhost:8080
. The background should be red. Also, if you open the styles.css file in SublimeText, you will see output css with:body{ background-color:#FF0000 }
- Test LiveReload and check if the browser color changes automatically if you change the value of
$bright
.
- initialize bower config
bower init
say yes to all - install foundation,
bower install -S foundation
- Copy the foundation
_settings.scss
partial from bower_components foundation into yoursass/partials
directory - At the top of your
styles.scss
file, import the settings partial:@import "partials/settings";
- Then import the Foundation components you want to use:
@import "foundation/components/[component name]";
Look at the main foundation.scss
in the bower_components foundation scss folder to see all the available components.
Copy over the necessary js files from bower_component/foundation/js/
into /public/js
. At minimum you need:
foundation.min.js
jquery.js
modernizer.js
However, if you are only using certain foundation components, you can opt to use only the ones required for the components instead.
Add necessary script tags to import the foundation, jquery, and modernizer js files to the bottom of your file, before the closing </body>
tag. It will look similar to the following, however your src paths may be slightly different:
<script src="/js/vendor/modernizer.js"></script>
<script src="/js/vendor/jquery.js"></script>
<script src="/js/foundation.min.js"></script>
Add the script to initialize foundation after the above scripts and before the closing </body>
tag.
<script>
$(document).foundation();
</script>
In order for the webpage to render and scale properly on mobile devices, add this meta tag to the <head>
:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- You may need to stop and restart gulp, since you added new files to the project.
- Look at
public/css/styles.css
. Check if all of the foundation components that you imported are compiled. - Drop in some Foundation markup that utilizes both css and js (like the top-bar) into your
index.html
and test if the component works.
Whenever you add new files to your public/
directory (like images or javascript), you may need to kill then restart your gulp task.
Once gulp, scss, and livereload are wired up correctly...
- Set up a
.gitignore
file in your root directory to make sure that Git ignores the following directories:node_modules/
andbower_components/
- Commit your new files