1
- const fs = require ( 'fs' ) ;
1
+ const fs = require ( 'node: fs' ) ;
2
2
const inclusiveLangPlugin = require ( '@11ty/eleventy-plugin-inclusive-language' ) ;
3
3
const cacheBuster = require ( '@mightyplow/eleventy-plugin-cache-buster' ) ;
4
+ const pluginSitemap = require ( '@quasibit/eleventy-plugin-sitemap' ) ;
4
5
const htmlmin = require ( 'html-minifier' ) ;
5
6
const { minify } = require ( 'terser' ) ;
6
7
const siteSettings = require ( './src/globals/site.json' ) ;
@@ -16,7 +17,15 @@ const dateFormatter = Intl.DateTimeFormat('en-US', {
16
17
} ) ;
17
18
18
19
module . exports = function ( eleventyConfig ) {
19
- eleventyConfig . addPassthroughCopy ( './src/css/tailwind.include.css' ) ;
20
+ const runMode = process . env . ELEVENTY_RUN_MODE ;
21
+ const isProduction = runMode === 'build' ;
22
+
23
+ eleventyConfig . addPlugin ( pluginSitemap , {
24
+ sitemap : {
25
+ hostname : siteSettings . url ,
26
+ } ,
27
+ } ) ;
28
+
20
29
eleventyConfig . addPassthroughCopy ( { public : './' } ) ;
21
30
22
31
eleventyConfig . addShortcode ( 'year' , function ( ) {
@@ -29,7 +38,7 @@ module.exports = function (eleventyConfig) {
29
38
30
39
eleventyConfig . addPlugin ( inclusiveLangPlugin ) ;
31
40
32
- if ( process . env . ELEVENTY_ENV === 'production' ) {
41
+ if ( isProduction ) {
33
42
eleventyConfig . addPlugin ( cacheBuster ( { outputDirectory : 'dist' } ) ) ;
34
43
35
44
eleventyConfig . addTransform ( 'htmlmin' , function ( content , outputPath ) {
@@ -45,37 +54,19 @@ module.exports = function (eleventyConfig) {
45
54
} ) ;
46
55
}
47
56
48
- eleventyConfig . addNunjucksAsyncFilter (
49
- 'jsmin' ,
50
- async function ( code , callback ) {
51
- if ( process . env . ELEVENTY_ENV === 'production' ) {
52
- try {
53
- const minified = await minify ( code ) ;
54
- callback ( null , minified . code ) ;
55
- } catch ( err ) {
56
- console . error ( 'Terser error: ' , err ) ;
57
- // Fail gracefully.
58
- callback ( null , code ) ;
59
- }
60
- } else {
61
- callback ( null , code ) ;
57
+ eleventyConfig . addAsyncFilter ( 'jsmin' , async function ( code ) {
58
+ if ( isProduction ) {
59
+ try {
60
+ const minified = await minify ( code ) ;
61
+ return minified . code ;
62
+ } catch ( err ) {
63
+ console . error ( 'Terser error: ' , err ) ;
64
+ // Fail gracefully.
65
+ return code ;
62
66
}
67
+ } else {
68
+ return code ;
63
69
}
64
- ) ;
65
-
66
- eleventyConfig . setBrowserSyncConfig ( {
67
- callbacks : {
68
- ready : function ( err , bs ) {
69
- bs . addMiddleware ( '*' , ( req , res ) => {
70
- const content_404 = fs . readFileSync ( 'dist/404.html' ) ;
71
- // Provides the 404 content without redirect.
72
- res . write ( content_404 ) ;
73
- // Add 404 http status code in request header.
74
- res . writeHead ( 404 , { 'Content-Type' : 'text/html' } ) ;
75
- res . end ( ) ;
76
- } ) ;
77
- } ,
78
- } ,
79
70
} ) ;
80
71
81
72
return {
0 commit comments