mirror of
https://github.com/d3ward/toolz.git
synced 2024-12-28 11:11:00 +08:00
400ca5533d
closes #89 closes #80 closes #78 - Updated hosts list - Added rules to .adblock file - Removed partner.ads script - Cosmetic and script tests set to 1 point each - Improved hosts test with fake 404 page
36 lines
1,007 B
JavaScript
36 lines
1,007 B
JavaScript
import { PurgeCSS } from 'purgecss'
|
|
import path from 'path'
|
|
import config from './config.js' // Make sure the config file is also compatible with ESM
|
|
import fs from 'fs'
|
|
import chalk from 'chalk'
|
|
|
|
const pages = config.pages
|
|
const options = pages.map((page) => {
|
|
const css = path.join(config.build, `css/${page}.css`)
|
|
const content = [
|
|
path.join(config.build, `${page}.html`),
|
|
path.join(config.build, `js/${page}.js`)
|
|
]
|
|
return {
|
|
css: [css],
|
|
content: content
|
|
}
|
|
})
|
|
|
|
Promise.all(options.map((option) => new PurgeCSS().purge(option))).then(
|
|
(results) => {
|
|
results.forEach((result, i) => {
|
|
const css = result[0].css
|
|
const cssFile = path.join(config.build, `css/${pages[i]}.css`)
|
|
console.log(chalk.green(`File: ${cssFile}`))
|
|
console.log(
|
|
`Original size: ${(
|
|
fs.statSync(path.join(config.build, `css/${pages[i]}.css`))
|
|
.size / 1024
|
|
).toFixed(2)}KB`
|
|
)
|
|
console.log(`Optimized size: ${(css.length / 1024).toFixed(2)}KB`)
|
|
fs.writeFileSync(cssFile, css)
|
|
})
|
|
}
|
|
)
|