View online at vam-fractal-main.surge.sh.
This visual style guide is built on top of Fractal, a project by Clearleft. Active development requires the latest LTS version (18.x) of Node.js to be installed.
The documentation for Fractal is super useful. Have a read through the Core Concept documentation before modifying.
Add the following to your project package.json
file, replacing the branch name (i.e., #main) if required, with any feature branch name or commit ID in the vam-fractal project that you want to use:
"vam-fractal": "vanda/vam-fractal#main"
Component modules have their own SASS and can also contain Javascript files which are imported directly from the vam-fractal node-module directory installed as a dependency in your project package.json
file. These assets should be compiled as required within the project itself.
Font and SVG (as an icon sprite) assets can be accessed by creation of symlinks. For example,
SVGs:
ln -s node_modules/vam-fractal/build/svg/vam-sprite.svg assets/svg
Fonts:
ln -s node_modules/vam-fractal/build/fonts assets/
After cloning this repository, in a terminal enter:
$ npm install
If you haven't read the documentation for Fractal yet, get over there now.
In a terminal enter:
$ npm run dev
- Compiled assets and other assets for distribution are linted and processed into a new root directory,
/build
- The Node.js environment variable is set to:
NODE_ENV=development
by prepending to the application initialisation command inpackage.json
. Compiled assets are generated with code sourcemaps but are not minified for ease of investigation in development mode. - The Fractal server is started and a local build is rendered at localhost:8000 - change the port number in the root
fractal.config.js
if required - The local build runs Webpack in watch mode, meaning that any changes to the component module SASS or Javascript files will result in the compilation to
/build
being updated - The Fractal server is started with the
server.sync
property set totrue
so changes to component module files will also cause a page refresh in the browser using Fractal's BrowserSync integration
It is possible to create a static build like that hosted at vam-fractal-main.surge.sh
In a terminal enter:
$ npm run build
- Compiled assets and other assets for distribution are linted and processed into a new or existing root directory,
/build
- Node.js environment variable is set to:
NODE_ENV=production
and compiled assets are minified. No code sourcemaps are produced. Filenames are appended with a 'cache busting' hash number - A Fractal 'static build' is generated using the component modules and the generated assets in the
/build
directory. This is processed into a new root directoy,/www
New Fractal modular components are added in src/components
-
Where the component contains a
_[name].scss
file, a reference to this stylesheet should be set insrc/assets/styles/vam-style.scss
.The Dart SASS compiler supports the SASS-preferred use of
@use
and@forward
directives in place of the imminently deprecated@import
statement. There should be no@import
statements used in the project. Note that commonly used SASS stylesheets for base rules, mixins, etc. are organised in their own directories and loaded using a single entry-point file_index.scss
within that directory. This allows these stylesheets to be namespaced and immediately identifiable in the component_[name].scss
file.For example, in
_[name].scss
@use "[path]/base"; .exmple-selector { @include base.typography-typeSetting(4, "regular"); }
Here we state that we want
_[name].scss
to be exposed to thebase
namespace. However, this namespace contains several stylesheets which themselves often contain groupings of variables, maps, functions and mixins, etc.So to further define within
_[name].scss
the source of our required object, in this case the mixintypeSetting()
, a single entry-point file atsrc/components/base/_index.scss
uses the@forward
directive to expose the SASS file atsrc/components/base/typography_typography.scss
with an alias:typography-
Use of an alias provides an immediate indication of the
typeSetting()
object location as being in the typography component stylesheet within thebase
namespace. -
If the new component contains its own Javascript file in the form of
_[name].js
then this should be registered insrc/assets/scripts/vam-scripts.js
-
The
[name].html
document should use the Nunjucks Javascript templating language -
Set variants of the component in the
[name].config.js
Fractal configuration file
The SASS is linted via stylelint. The configuration and custom rule set is found in /.stylelint.json
. When modifying or adding to the SASS please read through the documentation around the rules.
The standard shareable SASS configuration for styleint, stylelint-config-standard-scss is used. In an effort to adhere to this standard please only add to the /.stylelint.json
configuration if agreed and absolutely necessary.
The deployment and distribution will fail if the SASS linting fails.
To add a new SVG icon and add it to the SVG sprite:
- Save the SVG file into the
src/assets/svg
directory - Edit
src/components/base/icons/icons.config.js
, adding the name of the icon taken from the filename to the array
If a development build has been run and Webpack is watching files in src/assets
then the new SVG icon will be bundled immediately into the SVG sprite at build/svg/vam-sprite.svg
Running either the development build or creating a Fractal 'static build' will incorporate the new SVG icon into the SVG sprite. The SVG icon is optimised before addition into the sprite and the sprite itself is then minified for distribution.
- Clearleft
- This set up has been heavily inspired by Bits of 24 ways by Paul Robert Lloyd. Thank you.