Skip to content

alexanderkwright/gulp-boilerplate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gulp Boilerplate Build Status

My boilerplate for creating new web projects with Gulp.js. Forked from Todd Motto's GulpOSS with some additions from Mark Goodyear and Big Bite Creative and various tutorials around the web.

  • Lints and concatenates JS files.
  • Compiles Sass files and automatically adds vendor prefixes.
  • Exports both minified and expanded JS and CSS files with header info.
  • Generates SVG sprites.
  • Generates documentation.
  • Cleans up file directories.
  • Runs Jasmine unit tests and generates reports.
  • Includes a .travis.yml file for continuous integration with TravisCI.

Download Gulp Boilerplate

In This Documentation

  1. Getting Started
  2. File Structure
  3. Working with the Source Files
  4. Options & Settings
  5. Continuous Integration
  6. License

Getting Started

Dependencies

Make sure these are installed first.

Quick Start

  1. In bash/terminal/command line, cd into your project directory.
  2. Run npm install to install required files.
  3. When it's done installing, run one of the task runners to get going:
    • gulp manually compiles files and runs unit tests.
    • gulp watch automatically compiles files, runs unit tests, and applies changes using LiveReload.

File Structure

Add your files to the appropriate src subdirectories. Gulp will process and and compile them into dist.

  • Content in subdirectories under the js folder will be concatenated. For example, files in js/detects will compile into detects.js. Files directly under js will compile individually.
  • SVGs in the svg subdirectories of the svg directory will compile into icons.svg.
  • Assets in the assets directory will be copied as-is into the dist directory.
gulp-boilerplate/
|—— dist/
|   |—— css/
|   |   |—— myplugin.css
|   |   |—— myplugin.min.css
|   |—— js/
|   |   |—— classList.js
|   |   |—— classList.min.js
|   |   |—— myplugin.js
|   |   |—— myplugin.min.js
|   |—— svg/
|   |   |—— icons.svg
|   |—— # static assets
|—— docs/
|   |—— assets/
|   |—— dist/
|   |—— index.html
|   |—— # other docs
|—— src/
|   |—— docs/
|   |   |—— _templates/
|   |   |   |—— _header.html
|   |   |   |—— _footer.html
|   |   |—— assets/
|   |   |   |—— # doc-specific assets
|   |   |—— index.html
|   |   |—— # other docs
|   |—— js/
|   |   |—— classList.js
|   |   |—— myplugin.js
|   |—— sass/
|   |   |—— _config.scss
|   |   |—— _mixins.scss
|   |   |—— components/
|   |   |   |—— myplugin.scss
|   |—— svg/
|   |   |—— # svgs
|   |—— static/
|   |   |—— # static assets
|—— test/
|   |—— coverage/
|   |   |—— various files
|   |—— results/
|   |   |—— unit-tests.html
|   |—— spec/
|   |   |—— spec-myplugin.js
|—— .travis.yml
|—— gulfile.js
|—— index.html
|—— package.json
|—— README.md
|—— README-TEMPLATE.md

Working with the Source Files

Sass

Sass files are located in src > sass. Gulp generates minified and unminified CSS files. It also includes autoprefixer, which adds vendor prefixes for you if required by the last two versions of a browser.

JavaScript

JavaScript files are located 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 will also be concatenated into a single file. For example, files in js/detects will compile into detects.js. Files directly under js will compile individually.

Unit Testing

Gulp Boilerplate is set up for unit testing with Jasmine. Add your tests to test/spec/spec-myplugin.js. Adjust filenames and references as needed.

Unit test results are printed in terminal, but you can also view them in a browser under test/results/unit-tests.html. Get a report of how much of your scripts is covered by testing under test/coverage.

SVGs

SVG files placed in the src > svg directory will be optimized with SVGO and compiled into dist > svg as-is.

SVG files placed in subdirectories of src > svg will be ocmpiled into a single SVG sprite named after the parent directory. For example, files in src > svg > icons would compile into a single icons.svg file.

Documentation

Add HTML or markdown (.md or .markdown) files to your docs folder in src.

The _templates directory in src contains the _header.html and _footer.html templates. These are automatically added to the beginning and end of each documentation page. You can also add your own templates to the _templates directory. Include template files in your docs by writing @@include('path-to-file') on its own line in your markup (or markdown).

Files placed in the assets directory will be moved over as-is to the docs directory. The boilerplate will also add a copy of your dist files so you can use them in your documentation.

Options and Settings

Updating Project Details

Open up package.json to change the name, version, URL and other data about the project.

Changing the Header

Inside gulpfile.js, banner.full is the expanded header, while banner.min is included with minified content.

Changing the Directory Structure

Inside gulpfile.js you'll see a variable named paths. Adjust the paths to suit your workflow.

var paths = {
	input: 'src/**/*',
	output: 'dist/',
	scripts: {
		input: 'src/js/*',
		output: 'dist/js/'
	},
	styles: {
		input: 'src/sass/**/*.{scss,sass}',
		output: 'dist/css/'
	},
	svgs: {
		input: 'src/svg/**/*.svg',
		output: 'dist/svg/'
	},
	static: 'src/static/**',
	test: {
		input: 'src/js/**/*.js',
		karma: 'test/karma.conf.js',
		spec: 'test/spec/**/*.js',
		coverage: 'test/coverage/',
		results: 'test/results/'
	},
	docs: {
		input: 'src/docs/*.{html,md,markdown}',
		output: 'docs/',
		templates: 'src/docs/_templates/',
		assets: 'src/docs/assets/**'
	}
};

Continuous Integration

This boilerplate includes a configuration file for Travis CI, a continuous integration service for GitHub.

If you sign-up and activate it for your repository, Travis CI will run your build and execute any processes to make sure everything is working as expected. This is particularly useful when working with a team or managing open source projects with multiple contributors.

The .travis.yml file is pre-configured for the boilerplate's build system. Even if you add files or update the Gulp tasks, you shouldn't need to change anything for it to work.

How to Contribute

In lieu of a formal style guide, take care to maintain the existing coding style. Please apply fixes to both the development and production code. Don't forget to update the version number, and when applicable, the documentation.

License

The code is available under the MIT License.

About

My boilerplate for creating new web projects with Gulp.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 86.0%
  • CSS 13.8%
  • HTML 0.2%