This boilerplate is a ready-to-go front-end workflow to start a new project using the static site generator Eleventy and Webpack to bundle assets. Originally built for personal use, the project is very opinionated and is focus on SEO, performance and accessibility. Feel free to use and modify.
git clone https://github.com/dosbenjamin/eleventy-webpack-boilerplate
npm install
These variables are use across pages, configuration files and editable in .env
file.
# Title used accross all the project, to this will be added the page title
APP_TITLE = 'My new 11ty website'
# Only used in webmanifest
APP_SHORT_TITLE = 'New site'
# Sign that separates APP_TITLE and page title
APP_TITLE_DIVIDER = '—'
# Only used for author meta tag
APP_AUTHOR = 'John Doe'
# Used for canonical links, permalink of page will be added to this
APP_BASE_URL = 'https://example.com'
# Used in webmanifest and meta tag
APP_COLOR = '#fff'
# Name and location of favicon. By default it is located in the src folder
APP_FAVICON = 'favicon.png'
# Enable this to convert jpg/png to webp
APP_WEBP = true
.env.example
into .env
!
- Bundle assets with Webpack (check
webpack.config.js
) - Browserslist set to defaults (check
.browserslistrc
) - Cache-buster all the assets files
- Cache files and add an offline page as fallback with Service Worker (check
sw.js
) - Compile
*.scss
files into a singlemain.css
file - Convert
*.svg
files used in*.scss
intosprite.svg
- Copy
robots.txt
topublic
folder - Copy
.htaccess
topublic
folder - Generate favicons,
manifest.webmanifest
,browserconfig.xml
and inject in*.html
- Generate
sitemap.xml
and paste it inpublic
- Generate
*.html
with Eleventy (checkeleventy.js
) - Inject
main.css
path in.htaccess
for HTTP/2 Server Push - Inject resources hint in
*.html
to preload*.woff2
fonts - Inject SEO meta tags (Twitter and Open Graph) in
*.html
- Lint
*.js
files with ESLint (check.eslintrc.js
) - Lint
*.scss
files with Stylelint (check.stylelintrc.js
) - Live reload server on file changes with Browsersync
- Minify and transform
*.html
with PostHTML (check.posthtmlrc.js
) - Minify
main.js
with Terser - Optimize, prefix and minify
main.css
with PostCSS (check.postcssrc.js
) - Optimize images and convert
*.jpg
&*.png
to*.webp
with Imagemin (check.imageminrc.js
) - Precompress files with Brotli and Gzip (Zopfli)
- Transpile and optimize
*.js
into a singlemain.js
with Babel (check.babelrc.js
) - Use Nunjucks
.njk
as templating engine - Use sanitize.css as reset
<!-- Input / index.njk -->
<link href="{{ '/assets/css/main.css' | getPath }}" rel="stylesheet" />
<video width="1200">
<source src="{{ '/assets/videos/matteo-singing.webm' | getPath }}" type="video/webm">
<source src="{{ '/assets/videos/matteo-singing.mp4' | getPath }}" type="video/mp4">
</video>
<!-- Output / index.html -->
<link href="/assets/css/main.f3ef3fdf.css" rel="stylesheet" />
<video width="1200">
<source src="/assets/videos/matteo-singing.qm92kd09.webm" type="video/webm">
<source src="/assets/videos/matteo-singing.po0820qn.mp4" type="video/mp4">
</video>
Note: Can be use for any file that will be in public
<!-- Input / index.njk -->
<img src="{{ '/assets/images/maxou.jpg' | resize(200) }}" alt="Maxime at the beach">
<img src="{{ '/assets/images/maxou.webp' | resize(600) }}" alt="Maxime at the beach">
<!-- Output / index.html -->
<img src="/assets/images/maxou-200.dk9d65d1.jpg" alt="Maxime at the beach">
<img src="/assets/images/maxou-600.kj4kf923.webp" alt="Maxime at the beach">
⚠️ Be sure to haveAPP_WEBP = true
in.env
before using resize with*.webp
⚠️ Resize is not available for*.gif
. UseGetPath
instead.
npm run build
: lint and build inpublic
folder for productionnpm run clean
: cleanpublic
foldernpm run lint
: lint*.scss
and*.js
filesnpm run serve
: lint, watch and build on file changes
- JavaScript Standard (check
.eslintrc.js
) - Stylelint Standard + Custom (check
.stylelintrc.js
)