Skip to content

Instantly share code, notes, and snippets.

@adambankin
Last active December 31, 2015 06:29
Show Gist options
  • Save adambankin/7947558 to your computer and use it in GitHub Desktop.
Save adambankin/7947558 to your computer and use it in GitHub Desktop.

Webstack Front-End Build Process

Overview of Flow

When we run rock build it performs the following tasks for front-end:

Build

  1. rock --runtime=node08 run grunt build
    • Use Grunt and Bower to download all front-end dependencies;
    • Organize the downloaded files on the file system.

Install

  1. rock --runtime=node08 run grunt install
    • Concatenate & minify JS & CSS into new files;
    • Write the new files to the file system;
    • Create a list of paths to these new files;
    • Write the list as build_values.json on the file system.

Detail of Flow

Build

Use Grunt and Bower to download all front-end dependencies

Grunt is a task runner and Bower is a package manager. They are node tools that are installed during the rock build process. For more details, see the Resources section below.

Grunt's tasks are stored in /Gruntfile.js and Bower's list of dependencies are stored in /bower.json.

Webstack has two types of front-end dependencies:
a) 3rd party code such as bootstrap or jQuery
b) "swig modules" - standalone repos that contain HTML, CSS & JS for UI components such as the header login, or the header language switcher. These modules can be used by other products in the company like Footage, Music or Enterprise to give a consistent user experience across different Shutterstock products.

Grunt runs its Bower task, causing Bower to pull down CSS, JS, HTML, fonts and images to the requesting machine.

Organize the downloaded files on the file system

Once the files are received, they are organized into directories under /public/webstack/ and /views/.

Where the files are placed is decided through tasks in Gruntfile.js AND information in bower.json.

PATH PURPOSE
/public/webstack/css/vendor/src/shutterstrap/ CSS associated with "Shutterstrap"
/public/webstack/js/vendor/src/[dir]/ Includes all 3rd-party JavaScript, where [dir] is Bower's name for the 3rd party content. For example, /public/webstack/js/vendor/src/html5shiv/
/public/webstack/img/ Images associated with "Shutterstrap"
/public/webstack/fonts/[dir]/ Fonts associated with "Shutterstrap", where [dir] is the name of a font family
/public/webstack/css/ss-includes/ CSS associated with swig modules
/public/webstack/js/ss-includes/ JavaScript associated with swig modules
/views/ss-includes/ HTML associated with swig modules

The webstack repo also has its own JavaScript and CSS files. They are similary stored under /public/webstack/.

PATH PURPOSE
/public/webstack/js/implementation.js Sitewide JS
/public/webstack/js/page/src/ JS specific to a page
/public/webstack/css/implementation.css Sitewide CSS
/public/webstack/css/page/src/ CSS specific to a page

Install

Concatenate & minify JS & CSS into new files

Write the new files to the file system

Create a list of paths to these new files

Write the list as build_values.json on the file system

Resources

Grunt
A javascript task runner. It performs tasks like Compiling, Linting, Unit testing, Concatenation, Minification etc
http://gruntjs.com/ & http://mikemclin.net/install-grunt-js-task-runner/

Bower
Frontend package manager for the web. It exposes the package dependency model via an API that can be consumed by a more opinionated build stack.
http://bower.io/ & https://github.com/bower/bower

npm-shrinkwrap.json vs package.json
When npm install installs a package with a npm-shrinkwrap.json file in the package root, the shrinkwrap file (rather than package.json files) completely drives the installation of that package and all of its dependencies (recursively).
http://blog.nodejs.org/2012/02/27/managing-node-js-dependencies-with-shrinkwrap/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment