A clean foundational setup for your upcoming frontend project built on Webpack.
- Overview
- Getting Started
- Usage
- Scripts
- Running Tests
- Linting
- Webpack Configuration
- Browser Support
- IDE Configuration
- Built With
- Features
- Contributing
- License
This starter kit provides a foundational setup for your frontend projects using Webpack. It includes configurations for development and production builds, as well as linting and testing setups.
Ensure you have Node.js and npm installed on your machine.
-
Clone the repository:
git clone https://github.com/timothyguo86/webpack-starter.git
-
Install dependencies:
npm install
This script starts the webpack development server with Hot Module Replacement (HMR)
, allowing you to see changes in real-time without a full page reload. It also includes an inline source map
for easier debugging.
npm run dev
This script builds your project for production, optimizing and minifying the code.
npm run build
This script runs Jest tests. Jest
is configured to handle stylesheets through identity-obj-proxy and use babel-jest for JavaScript.
npm run test
This script runs ESLint to lint your JavaScript files in the src
directory and automatically fixes fixable issues. The default eslint
configuration is based on Airbnb's JS config with tweaks defined in the .eslintrc
.
npm run lint
This script was initially setup for installing the husky and lint-staged. It sets up the .husky
directory, which you can ignore. When you run git commit -m <message>
, Husky executes the .husky/pre-commit
script through lint-staged
. This ensures linting and other tasks are performed on staged git files before committing.
npm run prepare
This repository includes three webpack configuration files:
webpack.dev.js
: Configuration for local development.webpack.prod.js
: Configuration for production.webpack.common.js
: Shared configuration betweenwebpack.dev.js
andwebpack.prod.js
.
Feel free to customize these files based on your project requirements.
Modify the .browserslistrc
queries, e.g., last 2 versions
, to ensure compatibility with Babel and PostCSS bundling configurations.
Modify .editorconfig
to maintain consistent coding styles for multiple developers working on the same project across various IDEs.
- Webpack - Module bundler.
- Babel - JavaScript compiler.
- Jest - JavaScript testing framework.
- ESLint - JavaScript linting utility.
- Prettier - Code formatter.
- PostCSS - CSS tooling.
- SASS - CSS preprocessor.
- Autoprefixer - CSS Vendor Prefixes.
- CSSnano - CSS Minification Tool
- Husky - Git hooks.
- Lint-staged - Pre-commit hooks.
- modern-normalize - Normalize browsers' default style.
The build hashes the bundled _.css
and _.js
files, ensuring that the browser fetches the latest version whenever their content changes. This enhances cache management and website performance by efficiently handling file updates.
Utilizes modern-normalize, a modern alternative to traditional CSS resets or normalizations, ensuring consistent rendering across different browsers while maintaining a modern and clean baseline for styling. You can import the modern-normalize
CSS file into your main.scss
using the following directive:
// main.scss
// Import modern-normalize
@import 'modern-normalize/modern-normalize.css';
// Your other SCSS styles here
Feel free to contribute by opening issues or submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.