/eleventy-webpack-boilerplate

Starter kit for using Eleventy with webpack, backed by Forestry.

Primary LanguageJavaScriptMIT LicenseMIT

eleventy-webpack-boilerplate

Starter kit for using Eleventy with webpack, backed by Forestry.

Eleventy is a simpler static site generator, which does a beautiful job of scaffolding your static site. However, a web application is so much more; what about images, stylesheets, or scripts? This is where webpack, a static module bundler, comes in. By combining Eleventy with webpack, you can take your static site to the next level with minimal effort.

As a bonus, this project is preconfigured to work out of the box with Forestry, in case you use Forestry to edit your site content.

Installation

Recommended

This project is set-up as a Template Repository. Click the "Use this template" button to create your new static site from this repository.

Others

  1. Clone the repository using git clone https://github.com/vseventer/eleventy-webpack-boilerplate.
  2. Navigate to your project directory using cd eleventy-webpack-boilerplate.
  3. Install the dependencies using npm install.

This project supports both npm and yarn, feel free to use whichever package manager you're most comfortable with.

Getting Started

Please familiarize yourself with Eleventy and webpack, and you will recognize the source directory contains all you need to get started with your new static site.

Development

  • To start the development server, run npm start or npm run watch and navigate to http://localhost:8080.
  • To build your site just once (for production), run npm run build.

The development server, webpack-dev-server, is provided by webpack and set-up to work in sync with Eleventy.

Configuration

This project predefines a set of configuration files, which can be tweaked depending on your preferences.

package.json

The browserslist property reflects the browsers your static website supports, per browserslist.

The config block in package.json enumerates three directories:

  • input: the source of your web application.
  • intermediate: the output directory for Eleventy, and input directory for webpack. You should never directly modify contents in this directory.
  • output: the final build of your web application.

.babelrc

The Babel smart preset is used allowing you to use the latest JavaScript. Two separate plugins supporting (private) class methods and properties are added by default as well.

.eslintrc and src/.eslintrc

This project follows Airbnb configuration for ESLint. The source directory extends the base configuration, and makes sure you can use certain environment variables in your JavaScript, as supported by webpack.

Linting is ran on your configuration files, as well as the scripts in the source directory of your static site.

.stylelintrc

This project follows the recommended configuration for stylelint. Linting is ran as part of PostCSS as explained below.

eleventy.config.js

The Eleventy configuration file sets some sane defaults, as well as provide a boilerplate for how to add custom filters and tags. This project comes with one sample link custom Nunjucks tag.

postcss.config.js

The PostCSS configuration adds a number of plugins. Your stylesheets are linted with stylelint, processed with postcss-preset-env (which includes autoprefixer) before being optimized with PurgeCSS (production only).

webpack.config.babel.js

The webpack configuration defines how your assets are bundled together.

Content Management

Content of your site lives in the src/ directory by default.

If you are using Forestry to manage your content, import your site by following the steps in the Forestry Dashboard. This project is set-up so that the Instant Preview functionality of Forestry will work out of the box.

Alternatives

License

The MIT License (MIT)

Copyright (c) 2020 Mark van Seventer

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.