Skip to content

HTML and JS bundling via Webpack 4. HTML and JS live-reloading via webpack-dev-server. It's purpose is to provide a minimal Webpack 4 boilerplate which delivers both HTML and JS live-reloading in development.

aarnadlr/html-js-webpack4-boiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SIMPLE WEBPACK 4 BOILERPLATE

HTML and JS bundling via Webpack 4. HTML and JS live-reloading via webpack-dev-server.

This is a simple, functional boilerplate project centered around Webpack 4. It is configured to bundle javascript by webpack's default config (no specials js loaders used), and HTML bundling via html-loader and html-webpack-plugin.

INSTRUCTIONS:

Experience both HTML and JS live-reloading in development by running:

npm run start

Further information

How the project was built:

  1. TERMINAL COMMANDS:
$	mkdir <project> && cd $_

$	npm init -y

$	npm i webpack webpack-cli webpack-dev-server html-loader html-webpack-plugin --save-dev

$	mkdir src

$	touch src/index.js

$	touch src/index.html
  1. Added html5 boilerplate code inside index.html

  2. Added to package.json the new Webpack 4 npm scripts:

"scripts": {
  "start": "webpack-dev-server --mode development --open",
  "build": "webpack --mode production"
}
  1. Added webpack.config.js to the root of the folder.

  2. Added this config code, which gets Webpack to bundle and live-reload the js (by default), and the html (which needs both html-loader and html-wepack-plugin):

const HtmlWebPackPlugin = require("html-webpack-plugin");

module.exports = {
  module: {
    rules: [
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: { minimize: true }
          }
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html"
    })
  ]
};
  1. The boilerplate is complete! To experience both html and js live-reloading in development, run:
npm run start

Thank you and good luck!

a

About

HTML and JS bundling via Webpack 4. HTML and JS live-reloading via webpack-dev-server. It's purpose is to provide a minimal Webpack 4 boilerplate which delivers both HTML and JS live-reloading in development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published