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-boilerplatenpm 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
*.scssfiles into a singlemain.cssfile - Convert
*.svgfiles used in*.scssintosprite.svg - Copy
robots.txttopublicfolder - Copy
.htaccesstopublicfolder - Generate favicons,
manifest.webmanifest,browserconfig.xmland inject in*.html - Generate
sitemap.xmland paste it inpublic - Generate
*.htmlwith Eleventy (checkeleventy.js) - Inject
main.csspath in.htaccessfor HTTP/2 Server Push - Inject resources hint in
*.htmlto preload*.woff2fonts - Inject SEO meta tags (Twitter and Open Graph) in
*.html - Lint
*.jsfiles with ESLint (check.eslintrc.js) - Lint
*.scssfiles with Stylelint (check.stylelintrc.js) - Live reload server on file changes with Browsersync
- Minify and transform
*.htmlwith PostHTML (check.posthtmlrc.js) - Minify
main.jswith Terser - Optimize, prefix and minify
main.csswith PostCSS (check.postcssrc.js) - Optimize images and convert
*.jpg&*.pngto*.webpwith Imagemin (check.imageminrc.js) - Precompress files with Brotli and Gzip (Zopfli)
- Transpile and optimize
*.jsinto a singlemain.jswith Babel (check.babelrc.js) - Use Nunjucks
.njkas 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 = truein.envbefore using resize with*.webp⚠️ Resize is not available for*.gif. UseGetPathinstead.
npm run build: lint and build inpublicfolder for productionnpm run clean: cleanpublicfoldernpm run lint: lint*.scssand*.jsfilesnpm run serve: lint, watch and build on file changes
- JavaScript Standard (check
.eslintrc.js) - Stylelint Standard + Custom (check
.stylelintrc.js)
