Skip to content
Front-end React framework built with Webpack v4 and Babel 7.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
README.md
package-lock.json
package.json
postcss.config.js
webpack.config.js
webpack4.png

README.md

Webpack 4 + Babel 7 + React 16 Framework

Image

A front end React framework built with Webpack v4, Babel 7 and SCSS. The focus is on overall performance by making use of code splitting and minification of HTML, JavaScript, CSS and images.

General Information

This framework was built to easily create performant front end React projects using Webpack v4's built-in compression and minification tools as well as other plugins.

It combines Webpack's Hot Module Replacement and BrowserSync to get the best functionality of the two.

Bundle Analyzer is also included (commented out by default) for both production and development modes to test compiled bundle sizes.

A pre-made index.html file comes with the framework with auto-injection of CSS and JavaScript links as a part of the build process.

Autoprefixer is also included within the PostCSS config file and is set to default browser versions in the package.json file.

React v16 is preloaded, as is React Router v4.

Common Configuration

This framework uses a single webpack.config.js file which inserts/toggles functionality based on whether the mode is currently development or production (modes are set in the package.json scripts).

It leaves out an entry option due to using index.js as an entry point by default.

CSS is compiled down from SCSS using multiple loaders in sequence, including PostCSS with Autoprefixer built in. Smaller images are minimized and inlined as Base64.

HtmlWebpackPlugin is used to inject CSS and JavaScript into an existing index.html template file.

Development Mode

Hot reloading in the browser after any code changes is made available via Webpack's built-in Hot Module Replacement and BrowserSync working together to get the best of both.

Source mapping is provided for both CSS and JavaScript.

Production Mode

Code splitting is included to separate vendor/dependency code from a project's main JavaScript, and the [chunkhash] option is used in production mode filenames for vendor/dependency output files in order to enable cache busting to improve browser loading time.

JavaScript is minimized with help from UglifyJsPlugin, among other tools, and includes removal of console.logs and comments.

CSS is minimized with MiniCssExtractPlugin after SCSS is converted to CSS and the code is run thru Autoprefixer via PostCSS, and cssnano via OptimizeCssAssetsPlugin.

CleanWebpackPlugin allows for a clean build process without worrying about old files left in the dist folder.

Compilation "Trees"

HTML

The included index.html file is run thru HtmlWebpackPlugin to inject CSS and Javascript then converted to gzip with CompressionWebpackPlugin.

CSS

SCSS files are converted to CSS, run thru a PostCSS process using Autoprefixer and cssnano, and minified with MiniCssExtractPlugin (in production mode).

JavaScript

JavaScript is minified with UglifyJsPlugin and converted to gzip with CompressionWebpackPlugin.

Vendor, or dependency, code is split out from a project's JavaScript in production mode to improve browser load time and provide for cache busting.

To Do

Addition of ESLint and Stylelint configuration

You can’t perform that action at this time.