Skip to content

Commit

Permalink
Use the new eleventy-plugin-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 2, 2023
1 parent 9fa7458 commit c9595d8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
40 changes: 17 additions & 23 deletions _includes/layouts/base.njk
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,31 +14,25 @@
{#- <meta name="generator" content="{{ eleventy.generator }}"> #} {#- <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) Learn more: https://github.com/11ty/eleventy-plugin-bundle
<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.
#} #}

{#- 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> </head>
<body> <body>
<a href="#skip" class="visually-hidden">Skip to main content</a> <a href="#skip" class="visually-hidden">Skip to main content</a>
Expand Down
1 change: 1 addition & 0 deletions _includes/layouts/home.njk
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
layout: layouts/base.njk layout: layouts/base.njk
--- ---
<!-- Delete this message --> <!-- Delete this message -->
{%- css %}{% include "public/css/message-box.css" %}{% endcss %}
<div class="message-box"> <div class="message-box">
<ol> <ol>
<li>Edit the <code>_data/metadata.json</code> with your blog’s information.</li> <li>Edit the <code>_data/metadata.json</code> with your blog’s information.</li>
Expand Down
5 changes: 5 additions & 0 deletions _includes/layouts/post.njk
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,11 @@
--- ---
layout: layouts/base.njk 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> <h1>{{ title }}</h1>


<ul class="post-metadata"> <ul class="post-metadata">
Expand Down
2 changes: 2 additions & 0 deletions eleventy.config.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const markdownItAnchor = require("markdown-it-anchor");


const pluginRss = require("@11ty/eleventy-plugin-rss"); const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginBundle = require("@11ty/eleventy-plugin-bundle");
const pluginNavigation = require("@11ty/eleventy-navigation"); const pluginNavigation = require("@11ty/eleventy-navigation");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy"); const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");


Expand Down Expand Up @@ -31,6 +32,7 @@ module.exports = function(eleventyConfig) {
}); });
eleventyConfig.addPlugin(pluginNavigation); eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin); eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(pluginBundle);


// Filters // Filters
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => { eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@11ty/eleventy": "2.0.0-beta.2", "@11ty/eleventy": "2.0.0-beta.2",
"@11ty/eleventy-img": "^3.0.0", "@11ty/eleventy-img": "^3.0.0",
"@11ty/eleventy-navigation": "^0.3.5", "@11ty/eleventy-navigation": "^0.3.5",
"@11ty/eleventy-plugin-bundle": "^1.0.1",
"@11ty/eleventy-plugin-rss": "^1.2.0", "@11ty/eleventy-plugin-rss": "^1.2.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^4.2.0", "@11ty/eleventy-plugin-syntaxhighlight": "^4.2.0",
"luxon": "^3.2.1", "luxon": "^3.2.1",
Expand Down

0 comments on commit c9595d8

Please sign in to comment.