feat: minify html + js
This commit is contained in:
parent
d1b6b8cbea
commit
ee53cbdb26
6 changed files with 320 additions and 8 deletions
29
.eleventy.js
29
.eleventy.js
|
@ -3,8 +3,9 @@ import tablerIcons from '@cdransf/eleventy-plugin-tabler-icons'
|
|||
import markdownIt from 'markdown-it'
|
||||
import markdownItAnchor from 'markdown-it-anchor'
|
||||
import markdownItFootnote from 'markdown-it-footnote'
|
||||
import htmlmin from 'html-minifier-terser'
|
||||
import filters from './config/filters/index.js'
|
||||
import { copyErrorPages } from './config/events/index.js'
|
||||
import { copyErrorPages, minifyJsComponents } from './config/events/index.js'
|
||||
import { processContent, albumReleasesCalendar } from './config/collections/index.js'
|
||||
import { cssConfig } from './config/plugins/css-config.js'
|
||||
import { DateTime } from 'luxon'
|
||||
|
@ -92,6 +93,32 @@ export default async function (eleventyConfig) {
|
|||
|
||||
// events
|
||||
eleventyConfig.on('afterBuild', copyErrorPages)
|
||||
eleventyConfig.on('afterBuild', minifyJsComponents)
|
||||
|
||||
// transforms
|
||||
if (process.env.ELEVENTY_PRODUCTION) {
|
||||
eleventyConfig.addTransform('html-minify', (content, path) => {
|
||||
if (path && path.endsWith('.html')) {
|
||||
return htmlmin.minify(content, {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseWhitespace: true,
|
||||
decodeEntities: true,
|
||||
includeAutoGeneratedTags: false,
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
minifyURLs: true,
|
||||
noNewlinesBeforeTagClose: true,
|
||||
quoteCharacter: '"',
|
||||
removeComments: true,
|
||||
sortAttributes: true,
|
||||
sortClassName: true,
|
||||
useShortDoctype: true,
|
||||
processScripts: ['application/ld+json'], // minify JSON-LD scripts
|
||||
})
|
||||
}
|
||||
return content
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
passthroughFileCopy: true,
|
||||
|
|
Reference in a new issue