This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a3aac7
commit 4370d82
Showing
5 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {generate} from 'critical'; | ||
import {minify} from 'html-minifier'; | ||
import {readFileSync, writeFileSync} from 'fs'; | ||
import path from 'path'; | ||
|
||
// Inline critical CSS | ||
generate({ | ||
inline: true, | ||
base: 'out/', | ||
src: 'index.html', | ||
target: { | ||
html: 'index.html', | ||
uncritical: 'css/landing/style.css' | ||
}, | ||
dimensions: [ | ||
{ | ||
height: 200, | ||
width: 500 | ||
}, | ||
{ | ||
height: 900, | ||
width: 1024 | ||
}, | ||
{ | ||
height: 900, | ||
width: 1400 | ||
} | ||
], | ||
// ignore CSS rules | ||
ignoreInlinedStyles: true | ||
}).then(({css, html, uncritical}) => { | ||
console.log('Critical CSS generated', css.length); | ||
console.log('Uncritical CSS generated', uncritical.length); | ||
}).catch(err => { | ||
console.error('Critical CSS generation failed', err); | ||
}).then(() => { | ||
// Minify HTML | ||
const htmlPath = path.resolve('out/index.html'); | ||
const htmlContent = readFileSync(htmlPath, 'utf8'); | ||
const minifiedHTMLContent = minify(htmlContent, { | ||
collapseWhitespace: true, | ||
collapseInlineTagWhitespace: true, | ||
conservativeCollapse: true, | ||
minifyCSS: true, | ||
minifyJS: true, | ||
removeComments: true, | ||
useShortDoctype: true, | ||
html5: true | ||
}); | ||
|
||
writeFileSync(htmlPath, minifiedHTMLContent, 'utf8'); | ||
console.log('Wrote minified HTML to', htmlPath, minifiedHTMLContent.length); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters