Repository for Don't Blink Geek.
Requirements Node.js, npm, Gulp 4.x
Features
- Concatenate, minify, and lint JavaScript.
- Compile, minify, autoprefix, and lint Sass.
- Optimize images and SVGs.
- Copy static files and folders into your
dist
directory. - Automatically add headers and project details to JS and CSS files.
- Watch for file changes, and automatically recompile build and reload webpages.
- Turn tasks on and off in gulpfile.js
Notice
The original starter files can be found at https://travis-ci.org/cferdinandi/gulp-boilerplate. However, I have made changes to fit my personal preferences and needs.
This is my personal website but feel free to use this as a starting point for your own. You are free to copy the assets over and reuse everything with the exception of the logo, image files and video. If you're wondering why I don't .gitignore those files, it's due to the fact the host I use is directly referencing the files.
If you have questions or encounter any bugs, please leave a comment in the Issues section of the project. I will do my best to respond. However, I cannot provide assistance in setting up your work station if this is your first time using npm. There are plenty of resources already available online.
Note: if you've previously installed Gulp globally, run npm rm --global gulp
to remove it. Details here.
Make sure these are installed first.
- Node.js
- Gulp Command Line Utility
npm install --global gulp-cli
- In bash/terminal/command line,
cd
into your project directory. - Run
npm install
to install required files and dependencies. - When it's done installing, run one of the task runners to get going:
gulp
manually compiles files.gulp watch
automatically compiles files and applies changes using BrowserSync when you make changes to your source files.
Try it out. After installing, run gulp
to compile some test files into the dist
directory. Or, run gulp watch
and make some changes to see them recompile automatically.
Add your source files to the appropriate src
subdirectories. Gulp will process and and compile them into dist
.
- JavaScript files in the
src/js
directory will be compiled todist/js
. Files in subdirectories under thejs
folder will be concatenated. For example, files injs/detects
will compile intodetects.js
. - Files in the
src/sass
directory will be compiled todist/css
. - Image & SVG files placed in the
src/img
directory will be optimized with SVGO and compiled intodist/img
. - Files and folders placed in the
copy
directory will be copied as-is into thedist
directory.
The package.json
file holds all of the details about your project.
Some information is automatically pulled in from it and added to a header that's injected into the top of your JavaScript and CSS files.
{
"name": "project-name",
"version": "0.0.1",
"description": "A description for your project.",
"main": "./dist/your-main-js-file.js",
"author": {
"name": "YOUR NAME",
"url": "http://link-to-your-website.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "http://link-to-your-git-repo.com"
},
"devDependencies": {}
}
Note: devDependencies
are the dependencies Gulp uses. Don't change these or you'll break things.
Put your JavaScript files in the src/js
directory.
Files placed directly in the js
folder will compile directly to dist/js
as both minified and unminified files. Files placed in subdirectories under src/js
will also be concatenated into a single file. For example, files in js/detects
will compile into detects.js
.
Put your Sass files in the src/sass
directory.
Gulp generates minified and unminified CSS files. It also includes autoprefixer, which adds vendor prefixes for you.
Place images & SVG files in the src/img
directory.
These files will be optimized with gulp-imagemin and compiled into dist/img
.
Files and folders placed in the src/copy
directory will be copied as-is into dist
.
This is a great place to put HTML files and pre-compiled assets.
Options and settings are located at the top of the gulpfile.js
.
Set features under the settings
variable to true
to turn them on (default), and false
to turn them off.
/**
* Settings
* Turn on/off build features
*/
var settings = {
clean: true,
scripts: true,
styles: true,
images: true,
copy: true,
reload: true
};
Adjust the input
and output
paths for all of the Gulp tasks under the paths
variable. Paths are relative to the root project folder.
/**
* Paths to project folders
*/
var paths = {
input: 'src/',
output: 'dist/',
scripts: {
input: 'src/js/*',
output: 'dist/js/'
},
styles: {
input: 'src/sass/**/*.{scss,sass}',
output: 'dist/css/'
},
images: {
input: 'src/img/*.{jpg,gif,png,jpeg,svg}',
output: 'dist/img/'
},
copy: {
input: 'src/copy/**/*',
output: 'dist/'
},
reload: './dist/'
};
Gulp auto-injects a header into all of your JavaScript and CSS files with details from your package.json
file.
Unminified versions get a fat header, while minified files get a one-liner. You can change what's included under the banner
variable.
/**
* Template for banner to add to file headers
*/
var banner = {
full:
'/*!\n' +
' * <%= package.name %> v<%= package.version %>\n' +
' * <%= package.description %>\n' +
' * (c) ' + new Date().getFullYear() + ' <%= package.author.name %>\n' +
' * <%= package.license %> License\n' +
' * <%= package.repository.url %>\n' +
' */\n\n',
min:
'/*!' +
' <%= package.name %> v<%= package.version %>' +
' | (c) ' + new Date().getFullYear() + ' <%= package.author.name %>' +
' | <%= package.license %> License' +
' | <%= package.repository.url %>' +
' */\n'
};
The code is available under the MIT License.