Skip to content
This repository was archived by the owner on May 8, 2021. It is now read-only.

Commit 621191a

Browse files
committed
add purgeCSS option
1 parent aec8fc2 commit 621191a

File tree

4 files changed

+138
-6
lines changed

4 files changed

+138
-6
lines changed

examples/sapper/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Setting up Tailwind with Sapper is really simple, just install Tailwind and pocs
66
npm install tailwindcss postcss-cli --save-dev
77
```
88

9+
If you want to remove unused styles, add PurgeCSS as well
10+
11+
```
12+
npm install @fullhuman/postcss-purgecss
13+
```
14+
915
Create your Tailwind config file
1016

1117
```sh
@@ -17,8 +23,19 @@ Create a `postcss.config.js` file and add this to it
1723
```js
1824
const tailwindcss = require("tailwindcss");
1925

26+
// only needed if you want to purge
27+
const purgecss = require("@fullhuman/postcss-purgecss")({
28+
content: ["./src/**/*.svelte", "./src/**/*.html"],
29+
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
30+
});
31+
2032
module.exports = {
21-
plugins: [tailwindcss("./tailwing.js")]
33+
plugins: [
34+
tailwindcss("./tailwind.js"),
35+
36+
// only needed if you want to purge
37+
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
38+
]
2239
};
2340
```
2441

@@ -32,9 +49,14 @@ Next, create a CSS file for your Tailwind styles. You have to store in it static
3249

3350
Update your `package.json` with the custom scripts.
3451

52+
`build:tailwind is only needed if you want to purge`
53+
3554
```js
3655
"scripts": {
3756
"watch:tailwind": "postcss static/tailwind.css -o static/index.css -w",
57+
"build:tailwind": "NODE_ENV=production postcss static/tailwind.css -o static/index.css" ,
58+
"build": "npm run build:tailwind && sapper build --legacy",
59+
3860
}
3961
```
4062

examples/sapper/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "0.0.1",
55
"scripts": {
66
"watch:tailwind": "postcss static/tailwind.css -o static/index.css -w",
7-
"build": "sapper build --legacy",
7+
"build:tailwind": "NODE_ENV=production postcss static/tailwind.css -o static/index.css",
8+
"build": "npm run build:tailwind && sapper build --legacy",
89
"dev": "sapper dev",
910
"export": "sapper export --legacy",
1011
"start": "node __sapper__/build",
@@ -13,6 +14,7 @@
1314
"test": "run-p --race dev cy:run"
1415
},
1516
"dependencies": {
17+
"@fullhuman/postcss-purgecss": "^1.2.0",
1618
"compression": "^1.7.1",
1719
"polka": "^0.5.0",
1820
"sirv": "^0.4.0"

examples/sapper/postcss.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const tailwindcss = require("tailwindcss");
22

3+
// only needed if you want to purge
4+
const purgecss = require("@fullhuman/postcss-purgecss")({
5+
content: ["./src/**/*.svelte", "./src/**/*.html"],
6+
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
7+
});
8+
39
module.exports = {
4-
plugins: [tailwindcss("./tailwind.js")]
10+
plugins: [
11+
tailwindcss("./tailwind.js"),
12+
13+
// only needed if you want to purge
14+
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
15+
]
516
};

examples/sapper/yarn.lock

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,14 @@
647647
lodash "^4.17.11"
648648
to-fast-properties "^2.0.0"
649649

650+
"@fullhuman/postcss-purgecss@^1.2.0":
651+
version "1.2.0"
652+
resolved "https://registry.yarnpkg.com/@fullhuman/postcss-purgecss/-/postcss-purgecss-1.2.0.tgz#a3207a0e1812f8b56fa49fba5796a1020f2756a8"
653+
integrity sha512-An05jbnZVUrX+VVNniaNQtOuo/S7tyQu5x86itXTF+7kfMaGxglFGykFX2KCt2hcbJijbvfCval9IkPO19V1KA==
654+
dependencies:
655+
postcss "^7.0.14"
656+
purgecss "^1.3.0"
657+
650658
"@mrmlnc/readdir-enhanced@^2.2.1":
651659
version "2.2.1"
652660
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
@@ -729,7 +737,12 @@ ansi-regex@^3.0.0:
729737
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
730738
integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=
731739

732-
ansi-styles@^3.2.1:
740+
ansi-regex@^4.1.0:
741+
version "4.1.0"
742+
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
743+
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
744+
745+
ansi-styles@^3.2.0, ansi-styles@^3.2.1:
733746
version "3.2.1"
734747
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
735748
integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==
@@ -1017,6 +1030,15 @@ cliui@^4.0.0:
10171030
strip-ansi "^4.0.0"
10181031
wrap-ansi "^2.0.0"
10191032

1033+
cliui@^5.0.0:
1034+
version "5.0.0"
1035+
resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5"
1036+
integrity sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==
1037+
dependencies:
1038+
string-width "^3.1.0"
1039+
strip-ansi "^5.2.0"
1040+
wrap-ansi "^5.1.0"
1041+
10201042
code-point-at@^1.0.0:
10211043
version "1.1.0"
10221044
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
@@ -1236,6 +1258,11 @@ electron-to-chromium@^1.3.137:
12361258
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.146.tgz#d7010f417f87c2068fbb6700ae57767e2393eba7"
12371259
integrity sha512-BrUq08sx7eR4PCwLbjFxXmjcbDro6DSoc1pN8VCxq76U+o9JQzJlWH/NVtcpAqcktwpE5CVvMyqHqTQfCETNoQ==
12381260

1261+
emoji-regex@^7.0.1:
1262+
version "7.0.3"
1263+
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
1264+
integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==
1265+
12391266
end-of-stream@^1.1.0:
12401267
version "1.4.1"
12411268
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43"
@@ -1449,6 +1476,11 @@ get-caller-file@^1.0.1:
14491476
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
14501477
integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==
14511478

1479+
get-caller-file@^2.0.1:
1480+
version "2.0.5"
1481+
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
1482+
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
1483+
14521484
get-stdin@^6.0.0:
14531485
version "6.0.0"
14541486
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
@@ -2368,7 +2400,7 @@ os-homedir@^1.0.0:
23682400
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
23692401
integrity sha1-/7xJiDNuDoM94MFox+8VISGqf7M=
23702402

2371-
os-locale@^3.0.0:
2403+
os-locale@^3.0.0, os-locale@^3.1.0:
23722404
version "3.1.0"
23732405
resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a"
23742406
integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==
@@ -2635,6 +2667,16 @@ pump@^3.0.0:
26352667
end-of-stream "^1.1.0"
26362668
once "^1.3.1"
26372669

2670+
purgecss@^1.3.0:
2671+
version "1.3.0"
2672+
resolved "https://registry.yarnpkg.com/purgecss/-/purgecss-1.3.0.tgz#fc3c303df9a74a75547545b2c0da28a9ec63da00"
2673+
integrity sha512-0UMnr8aUsPO7RbzAT72UELRvwMHhadtuunDm7rcgRS6b8pCVO8yglIqikiYFwQk2XP606mk+GpjI1G74Auxgtg==
2674+
dependencies:
2675+
glob "^7.1.3"
2676+
postcss "^7.0.14"
2677+
postcss-selector-parser "^6.0.0"
2678+
yargs "^13.2.2"
2679+
26382680
rc@^1.2.7:
26392681
version "1.2.8"
26402682
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
@@ -2779,6 +2821,11 @@ require-main-filename@^1.0.1:
27792821
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
27802822
integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=
27812823

2824+
require-main-filename@^2.0.0:
2825+
version "2.0.0"
2826+
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
2827+
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
2828+
27822829
require-relative@^0.8.7:
27832830
version "0.8.7"
27842831
resolved "https://registry.yarnpkg.com/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de"
@@ -3139,6 +3186,15 @@ string-width@^1.0.1:
31393186
is-fullwidth-code-point "^2.0.0"
31403187
strip-ansi "^4.0.0"
31413188

3189+
string-width@^3.0.0, string-width@^3.1.0:
3190+
version "3.1.0"
3191+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
3192+
integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==
3193+
dependencies:
3194+
emoji-regex "^7.0.1"
3195+
is-fullwidth-code-point "^2.0.0"
3196+
strip-ansi "^5.1.0"
3197+
31423198
string.prototype.padend@^3.0.0:
31433199
version "3.0.0"
31443200
resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.0.0.tgz#f3aaef7c1719f170c5eab1c32bf780d96e21f2f0"
@@ -3169,6 +3225,13 @@ strip-ansi@^4.0.0:
31693225
dependencies:
31703226
ansi-regex "^3.0.0"
31713227

3228+
strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
3229+
version "5.2.0"
3230+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
3231+
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
3232+
dependencies:
3233+
ansi-regex "^4.1.0"
3234+
31723235
strip-bom@^3.0.0:
31733236
version "3.0.0"
31743237
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
@@ -3410,12 +3473,21 @@ wrap-ansi@^2.0.0:
34103473
string-width "^1.0.1"
34113474
strip-ansi "^3.0.1"
34123475

3476+
wrap-ansi@^5.1.0:
3477+
version "5.1.0"
3478+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09"
3479+
integrity sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==
3480+
dependencies:
3481+
ansi-styles "^3.2.0"
3482+
string-width "^3.0.0"
3483+
strip-ansi "^5.0.0"
3484+
34133485
wrappy@1:
34143486
version "1.0.2"
34153487
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
34163488
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
34173489

3418-
"y18n@^3.2.1 || ^4.0.0":
3490+
"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0:
34193491
version "4.0.0"
34203492
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"
34213493
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==
@@ -3433,6 +3505,14 @@ yargs-parser@^11.1.1:
34333505
camelcase "^5.0.0"
34343506
decamelize "^1.2.0"
34353507

3508+
yargs-parser@^13.1.0:
3509+
version "13.1.0"
3510+
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.0.tgz#7016b6dd03e28e1418a510e258be4bff5a31138f"
3511+
integrity sha512-Yq+32PrijHRri0vVKQEm+ys8mbqWjLiwQkMFNXEENutzLPP0bE4Lcd4iA3OQY5HF+GD3xXxf0MEHb8E4/SA3AA==
3512+
dependencies:
3513+
camelcase "^5.0.0"
3514+
decamelize "^1.2.0"
3515+
34363516
yargs@^12.0.1:
34373517
version "12.0.5"
34383518
resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13"
@@ -3450,3 +3530,20 @@ yargs@^12.0.1:
34503530
which-module "^2.0.0"
34513531
y18n "^3.2.1 || ^4.0.0"
34523532
yargs-parser "^11.1.1"
3533+
3534+
yargs@^13.2.2:
3535+
version "13.2.4"
3536+
resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.4.tgz#0b562b794016eb9651b98bd37acf364aa5d6dc83"
3537+
integrity sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg==
3538+
dependencies:
3539+
cliui "^5.0.0"
3540+
find-up "^3.0.0"
3541+
get-caller-file "^2.0.1"
3542+
os-locale "^3.1.0"
3543+
require-directory "^2.1.1"
3544+
require-main-filename "^2.0.0"
3545+
set-blocking "^2.0.0"
3546+
string-width "^3.0.0"
3547+
which-module "^2.0.0"
3548+
y18n "^4.0.0"
3549+
yargs-parser "^13.1.0"

0 commit comments

Comments
 (0)