1- const fs = require ( 'fs' ) ;
1+ const fs = require ( 'node: fs' ) ;
22const inclusiveLangPlugin = require ( '@11ty/eleventy-plugin-inclusive-language' ) ;
33const cacheBuster = require ( '@mightyplow/eleventy-plugin-cache-buster' ) ;
4+ const pluginSitemap = require ( '@quasibit/eleventy-plugin-sitemap' ) ;
45const htmlmin = require ( 'html-minifier' ) ;
56const { minify } = require ( 'terser' ) ;
67const siteSettings = require ( './src/globals/site.json' ) ;
@@ -16,7 +17,15 @@ const dateFormatter = Intl.DateTimeFormat('en-US', {
1617} ) ;
1718
1819module . 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+
2029 eleventyConfig . addPassthroughCopy ( { public : './' } ) ;
2130
2231 eleventyConfig . addShortcode ( 'year' , function ( ) {
@@ -29,7 +38,7 @@ module.exports = function (eleventyConfig) {
2938
3039 eleventyConfig . addPlugin ( inclusiveLangPlugin ) ;
3140
32- if ( process . env . ELEVENTY_ENV === 'production' ) {
41+ if ( isProduction ) {
3342 eleventyConfig . addPlugin ( cacheBuster ( { outputDirectory : 'dist' } ) ) ;
3443
3544 eleventyConfig . addTransform ( 'htmlmin' , function ( content , outputPath ) {
@@ -45,37 +54,19 @@ module.exports = function (eleventyConfig) {
4554 } ) ;
4655 }
4756
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 ;
6266 }
67+ } else {
68+ return code ;
6369 }
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- } ,
7970 } ) ;
8071
8172 return {
0 commit comments