A clean starter template for small frontend projects that use npm and Webpack. It gives you a ready-to-run dev server, production builds, HTML generation, CSS loading, basic asset handling, ESLint and Prettier setup, Jest testing with Babel, and a minimal src/ structure.
This template is intentionally lightweight: no framework, TypeScript, or Sass by default. Add those pieces only when a project actually needs them.
- Webpack 5 with separate common, development, and production configs
- Local development through Webpack Dev Server
- HTML generation from
src/template.html - CSS loading with
normalize.cssand a starterstyle.css - Basic image asset handling
- Optional GitHub Pages deployment through
gh-pages - ESLint with recommended JavaScript rules
- Prettier for consistent code formatting
- Jest with Babel for running tests that use ES module syntax
frontend-webpack-template/
├── src/
│ ├── index.js
│ ├── template.html
│ ├── modules/ # reusable app logic (import from here)
│ ├── tests/ # Jest test files (*.test.js)
│ └── styles/
│ ├── normalize.css
│ └── style.css
├── babel.config.js
├── webpack.common.js
├── webpack.dev.js
├── webpack.prod.js
├── eslint.config.js
├── .prettierignore
├── package.json
└── README.md
If this repository is marked as a GitHub template, click Use this template and create a new repository from it.
You can also clone it directly:
git clone https://github.com/soikat27/frontend-webpack-template.git
cd frontend-webpack-templateInstall dependencies:
npm installRun the development server:
npm run devBuild for production:
npm run buildRun tests:
npm testnpm run devstarts the local development server.npm run buildcreates a production build indist/.npm run deploybuilds the project and publishesdist/to GitHub Pages.npm testruns Jest tests insrc/tests/.npm run lintchecks JavaScript files with ESLint.npm run lint:fixruns ESLint and auto-fixes issues where possible.npm run formatformats project files with Prettier.npm run format:checkchecks formatting without changing files.
This template uses ESLint for linting and Prettier for formatting. Configuration lives in the project so every clone uses the same rules:
eslint.config.js— ESLint rules and ignored paths.prettierignore— files Prettier should skip (for exampledist/andnode_modules/)
Run checks from the terminal:
npm run lint
npm run formatFor editor support, install the ESLint and Prettier extensions in VS Code or Cursor. The extensions should detect the packages and config files in this repo. Use the project setup as the source of truth rather than relying only on global editor settings.
This template uses Jest with Babel so you can write tests using import/export syntax even though Jest runs in Node. Configuration:
babel.config.js— transpiles ES modules for Jest in memory (does not change your source files)src/tests/— put test files here (for examplesomething.test.js)src/modules/— put reusable logic here and import it from both app code and tests
Every test file should import Jest globals explicitly so ESLint stays happy:
import { test, expect } from "@jest/globals";See src/tests/demo.test.js for a working example. Copy that import line when you add new tests.
webpack.common.jscontains shared settings: entry point, HTML plugin, CSS loader, HTML loader, and asset rules.webpack.dev.jsadds development mode, dev server settings, and development source maps.webpack.prod.jsadds production mode, hashed output filenames, asset output naming, and disables production source maps.
The deploy script runs:
npm run build && gh-pages -d distThat builds the project, then publishes the generated dist/ folder to a gh-pages branch. Before deploying a project made from this template, update the homepage field in package.json to match the final repository URL.
After creating a new project from this template:
- Update the document title in
src/template.html - Add your app logic to
src/index.js - Put reusable functions and classes in
src/modules/ - Add tests in
src/tests/(usedemo.test.jsas a starting point) - Add project styles in
src/styles/style.css - Update package metadata in
package.json - Remove scripts or dependencies you do not need
- Soikat Saha
This project is licensed under the MIT License. See the LICENSE file for details.