solution • NodeJS — Bootstrap 4 and FontAwesome 5 via npm packages - martindubenet/wed-dev-design GitHub Wiki

This is a simple tutorial to refer as a vanilla set-up guide for a new bootstrap (v.4) project.
Tutorial references: How to customize Bootstrap v4 using node packages and Installing Bootstrap 4 Tutorial

$ command lines

Create the folder

$ cd ~/projects
$ mkdir project_folder
$ cd projects_folder

Generate the package.json for Node

This next command will launch the utility that will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults.

$ npm init
  1. package name : Leave_default_value
  2. version : Leave_default_value
  3. description : Describe this project
  4. entrey point : index.html
  5. test command : Leave_empty
  6. git repository : Optional
  7. keywords : Leave_empty
  8. author : My name
  9. licence : Leave_empty

Add npm dependencies

  1. autoprefixer to add prefixes where needed.
  2. Bootstrap the latest version 4.x.
  3. clean-css to create minified versions.
  4. node-sass to compile scss/Sass to css.
  5. postcss to actually use autoprefixer.
  6. stylelint to check the code for mistakes.

$ npm install <package_name> -D.

Note: The trailing -D at the end of command lines is to identify it as part of devDependency set

On at a time

$ npm install [email protected]
$ npm install autoprefixer -D
$ npm install clean-css -D
$ npm install node-sass -D
$ npm install postcss -D
$ npm install stylelint -D

Or all at once

npm install node-sass clean-css-cli autoprefixer postcss-cli stylelint stylelint-scss stylelint-order stylelint-config-standard stylelint-config-recommended-scss watch -D && npm install [email protected]

Note: This browser-sync paclkage will setup a static server and allow us to designate when the browser reloads as we save files. Since it was not part of the initial tutorial I'll need to test if it conflicts with the other packages listed above.

jQuery required

Since jQuery is required by Bootstrap but is available via Google's Developpers Library CDN it is usualy a good practice to load in the the <head> on the HTML templates instead of loading it as an npm dependency.

Load it as you want it:

Configuring the tools

Stylelintrc

All those Style Lint Rules defined what is allowed and what will throw an error. For example, "max-empty-lines": 2 will throw an error if you have 4 empty lines between two lines of code.

  1. Create the empty file: $ touch .stylelintrc
  2. Copy/Paste the content of Bootstrap's linth file from GitHub within your local .stylelintrc file.

Postcss

Postcss is required to run autopefixer which will add vendor prefixes when necessary, depending on the configuration you define.

To specify which browsers you wan’t to support you can add an array to the package.json file specifying version like this:

"browserslist": [    
    "last 1 major version",    
    ">= 1%",    
    "Chrome >= 45",    
    "Firefox >= 38",    
    "Edge >= 12",    
    "Explorer >= 10",    
    "iOS >= 9",    
    "Safari >= 9",    
    "Android >= 4.4",    
    "Opera >= 30"  
],

These are the default supported browsers by Bootstrap.

To make it possible to add prefixes when needed you need to create a postcss.config.js file and paste the following code within:

Create the file:

$ touch postcss.config.js

Copy/Paste this code:

'use strict'
//
module.exports = (ctx) => ({
    map: ctx.file.dirname.includes('examples') ? false : {
        inline: false,
        annotation: true,
        sourcesContent: true
    },
    plugins: {
        autoprefixer: { cascade: false }
    }
})

Now the tools are configured and we can run some scripts… but first we need some scss files. Easiest way, simply add a directory for the scss files and create import.scss where you will import all stylesheets, including Bootstrap from node_modules, and other project related stylesheet files. In that file import the bootstrap source files from the :

$ mkdir assets
$ cd assets
$ mkdir style
$ cd style
$ mkdir src
$ cd src
$ touch import.scss _bootstrap4.variables.scss _main.variables.scss _main.layout.scss
$ mkdir layout
$ cd layout
$ touch _main-header.scss _main-footer.scss

Set-up stylesheets

Edit import.scss

/*
 * IMPORT
 * Load
 */

@import '_main.variables';
@import '_bootstrap4.variables'; // load bootstrap sources within the project
@import '_main.layout';
@import 'layout/_main-header';
@import 'layout/_main-footer';
⚠️ **GitHub.com Fallback** ⚠️