Skip to content

Commit e512040

Browse files
committed
refactor: simplify purge to a plugin
1 parent b424fa2 commit e512040

File tree

5 files changed

+2197
-25
lines changed

5 files changed

+2197
-25
lines changed

_includes/base-simple-header.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>tinytown.studio</title>
7-
<link rel="stylesheet" href="/shed-css/index.css" />
7+
<link rel="stylesheet" href="/node_modules/shed-css/dist/index.css" />
88
<link rel="stylesheet" href="/main.css" />
99
<link rel="preconnect" href="https://fonts.googleapis.com" />
1010
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />

_lib/purge.js renamed to _plugins/purge.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import MinifyCSS from 'clean-css';
66

77
import { extname, join } from 'node:path';
88

9+
export async function purgePlugin(eleventyConfig) {
10+
eleventyConfig.on(
11+
'eleventy.after',
12+
async ({ directories, results, runMode, outputMode }) => {
13+
await purge(directories);
14+
}
15+
);
16+
}
17+
918
export async function purge(directories) {
1019
const inputDir = directories.output;
1120

eleventy.config.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { EleventyHtmlBasePlugin } from '@11ty/eleventy';
2-
import { purge } from './_lib/purge.js';
2+
import { purgePlugin } from './_plugins/purge.js';
3+
4+
import criticalCss from 'eleventy-critical-css';
35

46
export default function (eleventyConfig) {
7+
eleventyConfig.addPlugin(criticalCss);
58
eleventyConfig.addPassthroughCopy({
69
'./public/': '/',
710
});
@@ -10,11 +13,5 @@ export default function (eleventyConfig) {
1013
'/node_modules/shed-css/dist/index.css',
1114
});
1215
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
13-
14-
eleventyConfig.on(
15-
'eleventy.after',
16-
async ({ directories, results, runMode, outputMode }) => {
17-
await purge(directories);
18-
}
19-
);
16+
eleventyConfig.addPlugin(purgePlugin);
2017
}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
"license": "ISC",
1212
"description": "",
1313
"type": "module",
14-
"dependencies": {
14+
"devDependencies": {
1515
"@11ty/eleventy": "^3.0.0",
1616
"clean-css": "^5.3.3",
17-
"shed-css": "^1.4.0"
18-
},
19-
"devDependencies": {
17+
"shed-css": "^1.4.0",
2018
"@fullhuman/postcss-purgecss": "^7.0.2",
2119
"eleventy-plugin-purgecss": "^0.5.0",
2220
"postcss": "^8.5.1",

0 commit comments

Comments
 (0)