Skip to content

josh-clarke/pug-web-starter-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pug Web Starter Files

Open Issues Project Forks GitHub Stars GitHub license

These starter files can be used to quickly develop a prototype or flat-file website. The Pug template language is used for the HTML due to its terse structure and integration of JavaScript, and Sass is used for its flexibility and extended capabilities.

Highlights

  • Pug template language (formerly Jade) with a nice terse syntax
  • Sass for writing quick CSS
  • jQuery 3.6 included
  • PostCSS with the Autoprefixer and CSSNano extensions
  • Gulp 4 with a Babel gulpfile for ES6 syntax
  • Uses Yarn for Node package management
  • Relies on local node_modules instead of globals (except Yarn)

Requirements:

Quick Start

  1. Fork and/or clone the repository or download the ZIP file
    • git clone https://github.com/josh-clarke/pug-web-starter-files
  2. From the terminal inside the project folder, run yarn to install node modules
  3. Run yarn build (or gulp if you have gulp-cli installed globally) to build and watch for changes

Detailed Features

HTML

  • Pug template language (formerly Jade)
    • Extend/Include templates, Scripting, Mixins, Interpolation and more
  • Starter template based on HTML5 Boilerplate

CSS

JavaScript

  • Automatically includes and concatenates using gulp-include
  • jQuery included by default
  • IE Object Fit polyfill included
  • Uses gulp-include directives to bundle all scripts into one (see below)
  • Console log error prevention script included
  • Includes sourcemaps to trace errors to the source JS files

JavaScript files can be included into other files using //=require or //=include directives within the script file:

//=require plugins/prevent-console-errors.js
//=require ../../../node_modules/jquery/dist/jquery.js
  • Compresses JS files with Uglify
  • Sourcemaps is available but not configured for JavaScript
  • No linter; add your own if needed

Images

  • Images placed in ./src/assets/images/ are optimized by default with gulp-imagemin
    • Place directly in ./dist/assets/images/ if optimization is not needed or undesired

Templating

The best way to template with Pug, a HAML-like template language, is to extend from a base template. Base templates or partials may be prefixed with an underscore _ to prevent them from compiling into their own standalone templates. For example:

Base Template (Simplified): _base.pug

doctype html
html
block vars
  - var title = 'Fallback Title'
head
  title #{title}
body
  block content
    p Fallback content.

Extended Template: index.pug

extends _base.pug

block vars
  - var title = 'Hello World'

block content
  h1 Hello World!
  p You've reached my site!

Outputs (Simplified): index.html

<!DOCTYPE html>
<html>
  <head><title>Hello World</title></head>
  <body>
    <h1>Hello World!</h1>
    <p>You've reached my site!</p>
  </body>
</html>

You can also include partials with like this:

header
  include _partials/_hero-slider.pug

For more information, check out the Pug templating documentation.

Default Setup

By default, the following setup is used:

  • Working and Production directories (change in gulp-config.js)
    • src - Working directory
    • dist - Production directory (appears after first build)
      • This directory and its subfolders will not be created until the first gulp build command
    • assets - Assets directory for images, CSS, scripts
    • templates - Templates directory for Pug files
  • Gulp
    • yarn build or optional gulp command for default build with BrowserSync preview and watch files for changes
  • Pug Templates
    • Build templates in ./src/templates/ using either the .pug, or .jade extension
    • Name partials and base extends with a leading underscore _
    • Builds to ./dist/
  • CSS/Sass
    • Write Sass in ./src/assets/sass/
      • main.scss - Import all sass partials in here
      • base/ - Base styles
    • Name partials with a leading underscore _
    • Concatenates to ./dist/assets/css/main.css
    • Note: Use yarn add <module> --dev to maintain Sass libraries and link to them directly
      • Example: @import '../../../node_modules/modularscale-sass/stylesheets/modularscale';
  • JS
    • User script file in ./src/assets/js/scripts.js uses gulp-include directives to set bundle order of additional scripts
    • Place additional scripts in plugins/
    • Note: Use yarn add <module> --dev to maintain JS libraries and link to them directly
      • Example: //=require ../../../node_modules/jquery/dist/jquery.js
  • Images
    • Place images for processing in ./src/assets/images/
    • Runs imagemin default optimization (change in gulpfile.babel.js)
    • Outputs to ./dist/assets/images/

Working File Layout

./
 └ dist/                # distribution folder (appears after first build)
    └ assets
      └ css/      
        └ main.css      # main CSS file
      └ images/   
      └ js/
          └ scripts.js  # bundled scripts
 └ src/                 # working folder
    └ assets
      └ images/         # images to be optimized
      └ js/
          └ scripts.js  # use this for custom scripts
          └ plugins/    # use for non-package.json scripts
      └ scss/
          └ main.scss   # use this to include partials
          └ base/        
              └ _breakpoint-query.scss
              └ _buttons.scss
              └ _normalize.scss
              └ _scaffolding.scss
              └ _typography.scss
              └ _variables.scss
     └ templates/       # use for Pug templates
        └ _base.pug     # base template
        └ index.pug     # index.html, extends _base.pug

Miscellaneous

Saving New Components

Use the following commands to add modules or libraries to package.json. When you clone the repo to a new directory or machine, just run the yarn add command.

  • New project modules/libraries can be added with yarn add <package-name>
  • New build modules/libraries (such as gulp plugins) can be added with yarn add <package-name> --dev

If you want to shift all packages to their latest versions, you can do yarn upgrade. Do not do this unless you know what you are doing, as it could break your project.

End Notes

Based on:

Inspired by:

License

Released under an MIT license.