chore: improve minification
This commit is contained in:
parent
50da2beca1
commit
55326dab7d
8 changed files with 69 additions and 57 deletions
50
.eleventy.js
50
.eleventy.js
|
@ -22,7 +22,7 @@ const appVersion = require('./package.json').version
|
|||
export default async function (eleventyConfig) {
|
||||
eleventyConfig.addPlugin(syntaxHighlight)
|
||||
eleventyConfig.addPlugin(tablerIcons)
|
||||
eleventyConfig.addPlugin(cssConfig)
|
||||
if (process.env.ELEVENTY_PRODUCTION) eleventyConfig.addPlugin(cssConfig)
|
||||
|
||||
// quiet build output
|
||||
eleventyConfig.setQuietMode(true)
|
||||
|
@ -92,33 +92,31 @@ export default async function (eleventyConfig) {
|
|||
eleventyConfig.addShortcode('currentYear', () => DateTime.now().year)
|
||||
|
||||
// events
|
||||
eleventyConfig.on('afterBuild', copyErrorPages)
|
||||
eleventyConfig.on('afterBuild', minifyJsComponents)
|
||||
if (process.env.ELEVENTY_PRODUCTION) eleventyConfig.on('afterBuild', copyErrorPages)
|
||||
if (process.env.ELEVENTY_PRODUCTION) 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
|
||||
})
|
||||
}
|
||||
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