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

Commit 31333ce

Browse files
committed
added svelte setup
1 parent 301a787 commit 31333ce

File tree

14 files changed

+38242
-0
lines changed

14 files changed

+38242
-0
lines changed

examples/svelte/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
node_modules
3+
public/bundle.*

examples/svelte/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Svelte
2+
3+
Setting up Tailwind with svelte is really simple, just install Tailwind and pocstcss-cli:
4+
5+
```sh
6+
npm install tailwindcss postcss-cli --save-dev
7+
```
8+
9+
If you want to remove unused styles, add PurgeCSS as well
10+
11+
```
12+
npm install @fullhuman/postcss-purgecss
13+
```
14+
15+
Create your Tailwind config file
16+
17+
```sh
18+
./node_modules/.bin/tailwind init tailwind.js
19+
```
20+
21+
Create a `postcss.config.js` file and add this to it
22+
23+
```js
24+
const tailwindcss = require("tailwindcss");
25+
26+
// only needed if you want to purge
27+
const purgecss = require("@fullhuman/postcss-purgecss")({
28+
content: ["./src/**/*.svelte", "./public/**/*.html"],
29+
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
30+
});
31+
32+
module.exports = {
33+
plugins: [
34+
tailwindcss("./tailwind.js"),
35+
36+
// only needed if you want to purge
37+
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
38+
]
39+
};
40+
```
41+
42+
Next, create a CSS file for your Tailwind styles. You have to store in it public folder `public/tailwind.css` and add this to it :
43+
44+
```css
45+
@tailwind base;
46+
@tailwind components;
47+
@tailwind utilities;
48+
```
49+
50+
Update your `package.json` with the custom scripts.
51+
52+
`build:tailwind is only needed if you want to purge`
53+
54+
```js
55+
"scripts": {
56+
"watch:tailwind": "postcss public/tailwind.css -o public/index.css -w",
57+
"build:tailwind": "NODE_ENV=production postcss public/tailwind.css -o public/index.css",
58+
"dev": "run-p start:dev autobuild watch:build",
59+
"build": "npm run build:tailwind && rollup -c",
60+
61+
}
62+
```
63+
64+
Finally, add a stylesheet link to your `public/index.html` file
65+
66+
```html
67+
<link rel="stylesheet" href="index.css" />
68+
```
69+
70+
## Project setup
71+
72+
```
73+
npm install
74+
```
75+
76+
### Compiles and hot-reloads for development
77+
78+
```
79+
npm run dev
80+
```
81+
82+
### Compiles and minifies for production
83+
84+
```
85+
npm run build
86+
```

examples/svelte/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "svelte-app",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"npm-run-all": "^4.1.5",
6+
"postcss-cli": "^6.1.2",
7+
"rollup": "^1.10.1",
8+
"rollup-plugin-commonjs": "^9.3.4",
9+
"rollup-plugin-livereload": "^1.0.0",
10+
"rollup-plugin-node-resolve": "^4.2.3",
11+
"rollup-plugin-svelte": "^5.0.3",
12+
"rollup-plugin-terser": "^4.0.4",
13+
"sirv-cli": "^0.4.0",
14+
"svelte": "^3.0.0",
15+
"tailwindcss": "^1.0.3"
16+
},
17+
"scripts": {
18+
"watch:tailwind": "postcss public/tailwind.css -o public/index.css -w",
19+
"build:tailwind": "NODE_ENV=production postcss public/tailwind.css -o public/index.css",
20+
"dev": "run-p start:dev autobuild watch:tailwind",
21+
"build": "npm run build:tailwind && rollup -c",
22+
"autobuild": "rollup -c -w",
23+
"start": "sirv public",
24+
"start:dev": "sirv public --dev"
25+
},
26+
"dependencies": {
27+
"@fullhuman/postcss-purgecss": "^1.2.0"
28+
}
29+
}

examples/svelte/postcss.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const tailwindcss = require("tailwindcss");
2+
3+
// only needed if you want to purge
4+
const purgecss = require("@fullhuman/postcss-purgecss")({
5+
content: ["./src/**/*.svelte", "./public/**/*.html"],
6+
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
7+
});
8+
9+
module.exports = {
10+
plugins: [
11+
tailwindcss("./tailwind.js"),
12+
13+
// only needed if you want to purge
14+
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
15+
]
16+
};

examples/svelte/public/favicon.png

3.05 KB
Loading

examples/svelte/public/global.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
html, body {
2+
position: relative;
3+
width: 100%;
4+
height: 100%;
5+
}
6+
7+
body {
8+
color: #333;
9+
margin: 0;
10+
padding: 8px;
11+
box-sizing: border-box;
12+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13+
}
14+
15+
a {
16+
color: rgb(0,100,200);
17+
text-decoration: none;
18+
}
19+
20+
a:hover {
21+
text-decoration: underline;
22+
}
23+
24+
a:visited {
25+
color: rgb(0,80,160);
26+
}
27+
28+
label {
29+
display: block;
30+
}
31+
32+
input, button, select, textarea {
33+
font-family: inherit;
34+
font-size: inherit;
35+
padding: 0.4em;
36+
margin: 0 0 0.5em 0;
37+
box-sizing: border-box;
38+
border: 1px solid #ccc;
39+
border-radius: 2px;
40+
}
41+
42+
input:disabled {
43+
color: #ccc;
44+
}
45+
46+
input[type="range"] {
47+
height: 0;
48+
}
49+
50+
button {
51+
background-color: #f4f4f4;
52+
outline: none;
53+
}
54+
55+
button:active {
56+
background-color: #ddd;
57+
}
58+
59+
button:focus {
60+
border-color: #666;
61+
}

0 commit comments

Comments
 (0)