Use the new eleventy-plugin-bundle

This commit is contained in:
Zach Leatherman 2023-02-02 17:35:18 -06:00
parent 9fa7458062
commit c9595d8f42
5 changed files with 26 additions and 23 deletions

View File

@ -14,31 +14,25 @@
{#- <meta name="generator" content="{{ eleventy.generator }}"> #}
{#-
Choices for CSS:
CSS bundles are provided via the eleventy-plugin-bundle plugin:
1. You can add to them using `{% css %}`
2. You can get from them using `{% getBundle "css" %}` or `{% getBundleFileUrl "css" %}`
1. External files (best with local dev server live reload)
<link rel="stylesheet" href="/css/index.css">
<link rel="stylesheet" href="/css/message-box.css">
<link rel="stylesheet" href="/css/prism-okaidia.css">
<link rel="stylesheet" href="/css/prism-diff.css">
2. Inlined (fastest site performance in production)
#}
<style>
{% include "public/css/index.css" %}
{% include "public/css/message-box.css" %}
{% include "node_modules/prismjs/themes/prism-okaidia.css" %}
{% include "public/css/prism-diff.css" %}
</style>
{#
3. You could even swap between the two methods above using {% if eleventy.env.runMode === "serve" %}
4. Concatenate CSS to one file (site performance is slower than 2 but faster than 1):
https://www.11ty.dev/docs/quicktips/concatenate/
5. Use a bundler
e.g. Vite https://www.11ty.dev/docs/server-vite/
Or search for additional community plugins for esbuild, rollup, webpack, etc.
Learn more: https://github.com/11ty/eleventy-plugin-bundle
#}
{#- Add to the CSS bundle #}
{%- css %}{% include "public/css/index.css" %}{% endcss %}
{%- css %}{# add your own CSS! #}{% endcss %}
{#- Render the CSS bundle #}
{%- if eleventy.env.runMode === "serve" %}
{# External files (local dev live reload will refresh without page reload) #}
<link rel="stylesheet" href="{% getBundleFileUrl "css" %}">
{%- else %}
{# Inlined CSS (fastest site performance in production) #}
<style>{% getBundle "css" %}</style>
{%- endif %}
</head>
<body>
<a href="#skip" class="visually-hidden">Skip to main content</a>

View File

@ -2,6 +2,7 @@
layout: layouts/base.njk
---
<!-- Delete this message -->
{%- css %}{% include "public/css/message-box.css" %}{% endcss %}
<div class="message-box">
<ol>
<li>Edit the <code>_data/metadata.json</code> with your blogs information.</li>

View File

@ -1,6 +1,11 @@
---
layout: layouts/base.njk
---
{%- css %}
/* Only include the syntax highlighter CSS on blog posts */
{% include "node_modules/prismjs/themes/prism-okaidia.css" %}
{% include "public/css/prism-diff.css" %}
{%- endcss %}
<h1>{{ title }}</h1>
<ul class="post-metadata">

View File

@ -3,6 +3,7 @@ const markdownItAnchor = require("markdown-it-anchor");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginBundle = require("@11ty/eleventy-plugin-bundle");
const pluginNavigation = require("@11ty/eleventy-navigation");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
@ -31,6 +32,7 @@ module.exports = function(eleventyConfig) {
});
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(pluginBundle);
// Filters
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {

View File

@ -35,6 +35,7 @@
"@11ty/eleventy": "2.0.0-beta.2",
"@11ty/eleventy-img": "^3.0.0",
"@11ty/eleventy-navigation": "^0.3.5",
"@11ty/eleventy-plugin-bundle": "^1.0.1",
"@11ty/eleventy-plugin-rss": "^1.2.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^4.2.0",
"luxon": "^3.2.1",