Install:
npm i -D purgecss
Di package.json
:
"scripts": {
"purgecss": "purgecss --css public/dist/bootstrap.min.css --content src/**/*.svelte --output public/dist2",
"build": "routify -b --dynamic-imports && rollup -c && npm run purgecss && node script/salin.js && node script/pakaiPurge.js",
},
Buat file public/dist2/.hello
Di .gitignore
:
/public/dist2/bootstrap.min.css
Tambahkan di dist/global.css
:
body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;text-align:left;background-color:#fff}
Isi dari script/pakaiPurge.js
:
fs = require('fs')
namaFile = 'hasil/index.html'
fs.readFile(namaFile, 'utf8', (_, x) => {
x = x.replace('/dist/bootstrap.min.css', '/dist2/bootstrap.min.css')
fs.writeFile(namaFile, x, 'utf8', () => {})
})
Hasil: https://svelte-brown.vercel.app/
Catatan: Dia kalau di Svelte kita pakai dynamic class (nggak ditulis langsung di htmlnya, nama classnya), purgecss nggak bisa deteksi. Solusinya pakai whitelist di option purgecss (ada di Google tutorialnya)
Top comments (0)