Webpack

This Webpack information is not referenced from the general menu as it’s supplemental information not directly related to Fat-Free or Bootstrap (the purpose for this site). It is linked from the Development section.

While I don’t use Webpack 5’s capability for things like templates for building single-page webapps, I do use it in this and other projects to:

  • combine JavaScript files into a single, minified file
  • combine CSS into a single, minified file
  • process SCSS files into a single, minified CSS file

For this site, I use Webpack to combine jQuery, the jQuery easing plugin, Bootstrap, and a site-specific JavaScript file into a single, minified JavaScript file with source map and I use Glenn Marks’ Live Sass Compiler extension for VS Code to process the SCSS.

What I want is one setup with three script commands in the package.json file to process JavaScript, SCSS, and CSS (rather than using online minifiers, which don't have maps).

Note on running scripts

Some Webpack videos on YouTube use npm start while others use npm run start to run the start script in package.json.

If there isn’t a start script in package.json (or there isn’t a package.json file) then npm start is a short-cut for running node server.js. If there is a start script in package.json, then npm runs that script.

Executing npm run start also runs the start script, using the run-script command (run is an alias for run-script) to run the script.

It’s probably simplest to always use npm run script-name.

Installing stuff for Webpack

Install the following:

  • npm install --save-dev webpack webpack-cli
  • npm install --save-dev babel-loader @babel/core @babel/preset-env
  • npm install --save-dev expose-loader
  • npm install --save jquery
  • npm install --save-dev style-loader css-loader
  • npm install --save-dev sass sass-loader
    • I think sass is the new one (dart sass)
  • npm install --save-dev mini-css-extract-plugin
  • npm install --save-dev css-minimizer-webpack-plugin