├── .gitignore ├── public ├── favicon.png ├── index.html └── global.css ├── postcss.config.js ├── src ├── Tailwindcss.svelte ├── main.js └── App.svelte ├── tailwind.config.js ├── package.json ├── rollup.config.js ├── README.md └── scripts └── setupTypeScript.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /public/build/ 3 | 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarioglu/svelte-tailwindcss-template/HEAD/public/favicon.png -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /src/Tailwindcss.svelte: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import App from './App.svelte'; 2 | 3 | const app = new App({ 4 | target: document.body, 5 | props: { 6 | name: 'world' 7 | } 8 | }); 9 | 10 | export default app; -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Svelte app 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | purge: { 3 | enabled: !process.env.ROLLUP_WATCH, 4 | mode: 'all', 5 | content: ['./**/**/*.html', './**/**/*.svelte'], 6 | 7 | options: { 8 | whitelistPatterns: [/svelte-/], 9 | defaultExtractor: (content) => 10 | [...content.matchAll(/(?:class:)*([\w\d-/:%.]+)/gm)].map(([_match, group, ..._rest]) => group), 11 | }, 12 | }, 13 | darkMode: false, // or 'media' or 'class' 14 | theme: { 15 | extend: {}, 16 | }, 17 | variants: { 18 | extend: {}, 19 | }, 20 | plugins: [], 21 | } 22 | -------------------------------------------------------------------------------- /src/App.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 |
9 |

Hello {name}!

10 |

Visit the Svelte tutorial to learn how to build Svelte apps.

11 |
12 | 13 | 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "svelte-app", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "build": "rollup -c", 6 | "dev": "rollup -c -w", 7 | "start": "sirv public" 8 | }, 9 | "devDependencies": { 10 | "@rollup/plugin-commonjs": "^16.0.0", 11 | "@rollup/plugin-node-resolve": "^10.0.0", 12 | "autoprefixer": "^10.1.0", 13 | "postcss": "^8.2.2", 14 | "postcss-load-config": "^3.0.0", 15 | "rollup": "^2.3.4", 16 | "rollup-plugin-css-only": "^3.1.0", 17 | "rollup-plugin-livereload": "^2.0.0", 18 | "rollup-plugin-svelte": "^7.0.0", 19 | "rollup-plugin-terser": "^7.0.0", 20 | "svelte": "^3.0.0", 21 | "svelte-preprocess": "^4.6.1", 22 | "tailwindcss": "^2.0.2" 23 | }, 24 | "dependencies": { 25 | "sirv-cli": "^1.0.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /public/global.css: -------------------------------------------------------------------------------- 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 | -webkit-padding: 0.4em 0; 36 | padding: 0.4em; 37 | margin: 0 0 0.5em 0; 38 | box-sizing: border-box; 39 | border: 1px solid #ccc; 40 | border-radius: 2px; 41 | } 42 | 43 | input:disabled { 44 | color: #ccc; 45 | } 46 | 47 | button { 48 | color: #333; 49 | background-color: #f4f4f4; 50 | outline: none; 51 | } 52 | 53 | button:disabled { 54 | color: #999; 55 | } 56 | 57 | button:not(:disabled):active { 58 | background-color: #ddd; 59 | } 60 | 61 | button:focus { 62 | border-color: #666; 63 | } 64 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import svelte from 'rollup-plugin-svelte'; 2 | import commonjs from '@rollup/plugin-commonjs'; 3 | import resolve from '@rollup/plugin-node-resolve'; 4 | import livereload from 'rollup-plugin-livereload'; 5 | import { terser } from 'rollup-plugin-terser'; 6 | import css from 'rollup-plugin-css-only'; 7 | import sveltePreprocess from 'svelte-preprocess'; 8 | 9 | const production = !process.env.ROLLUP_WATCH; 10 | 11 | function serve() { 12 | let server; 13 | 14 | function toExit() { 15 | if (server) server.kill(0); 16 | } 17 | 18 | return { 19 | writeBundle() { 20 | if (server) return; 21 | server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { 22 | stdio: ['ignore', 'inherit', 'inherit'], 23 | shell: true 24 | }); 25 | 26 | process.on('SIGTERM', toExit); 27 | process.on('exit', toExit); 28 | } 29 | }; 30 | } 31 | 32 | export default { 33 | input: 'src/main.js', 34 | output: { 35 | sourcemap: true, 36 | format: 'iife', 37 | name: 'app', 38 | file: 'public/build/bundle.js' 39 | }, 40 | plugins: [ 41 | svelte({ 42 | preprocess: sveltePreprocess({ postcss: true }), 43 | compilerOptions: { 44 | // enable run-time checks when not in production 45 | dev: !production 46 | } 47 | }), 48 | // we'll extract any component CSS out into 49 | // a separate file - better for performance 50 | css({ output: 'bundle.css' }), 51 | 52 | // If you have external dependencies installed from 53 | // npm, you'll most likely need these plugins. In 54 | // some cases you'll need additional configuration - 55 | // consult the documentation for details: 56 | // https://github.com/rollup/plugins/tree/master/packages/commonjs 57 | resolve({ 58 | browser: true, 59 | dedupe: ['svelte'] 60 | }), 61 | commonjs(), 62 | 63 | // In dev mode, call `npm run start` once 64 | // the bundle has been generated 65 | !production && serve(), 66 | 67 | // Watch the `public` directory and refresh the 68 | // browser on changes when not in production 69 | !production && livereload('public'), 70 | 71 | // If we're building for production (npm run build 72 | // instead of npm run dev), minify 73 | production && terser() 74 | ], 75 | watch: { 76 | clearScreen: false 77 | } 78 | }; 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *Looking for a shareable component template? Go here --> [sveltejs/component-template](https://github.com/sveltejs/component-template)* 2 | 3 | --- 4 | 5 | # svelte-tailwindcss-template 6 | 7 | This is a fork of Svelte's project template to enable usage of Tailwindcss. Refer to https://github.com/sveltejs/template for more info. 8 | 9 | To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): 10 | 11 | ```bash 12 | npx degit sarioglu/svelte-tailwindcss-template svelte-app 13 | cd svelte-app 14 | ``` 15 | 16 | _Note that you will need to have [Node.js](https://nodejs.org) installed._ 17 | 18 | ## Get started 19 | 20 | Install the dependencies... 21 | 22 | ```bash 23 | cd svelte-app 24 | npm install 25 | ``` 26 | 27 | ...then start [Rollup](https://rollupjs.org): 28 | 29 | ```bash 30 | npm run dev 31 | ``` 32 | 33 | Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. 34 | 35 | By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. 36 | 37 | If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense. 38 | 39 | ## Building and running in production mode 40 | 41 | To create an optimised version of the app: 42 | 43 | ```bash 44 | npm run build 45 | ``` 46 | 47 | You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com). 48 | 49 | 50 | ## Single-page app mode 51 | 52 | By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere. 53 | 54 | If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json: 55 | 56 | ```js 57 | "start": "sirv public --single" 58 | ``` 59 | 60 | ## Using TypeScript 61 | 62 | This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with: 63 | 64 | ```bash 65 | node scripts/setupTypeScript.js 66 | ``` 67 | 68 | Or remove the script via: 69 | 70 | ```bash 71 | rm scripts/setupTypeScript.js 72 | ``` 73 | 74 | ## Deploying to the web 75 | 76 | ### With [Vercel](https://vercel.com) 77 | 78 | Install `vercel` if you haven't already: 79 | 80 | ```bash 81 | npm install -g vercel 82 | ``` 83 | 84 | Then, from within your project folder: 85 | 86 | ```bash 87 | cd public 88 | vercel deploy --name my-project 89 | ``` 90 | 91 | ### With [surge](https://surge.sh/) 92 | 93 | Install `surge` if you haven't already: 94 | 95 | ```bash 96 | npm install -g surge 97 | ``` 98 | 99 | Then, from within your project folder: 100 | 101 | ```bash 102 | npm run build 103 | surge public my-project.surge.sh 104 | ``` 105 | -------------------------------------------------------------------------------- /scripts/setupTypeScript.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | /** This script modifies the project to support TS code in .svelte files like: 4 | 5 | 8 | 9 | As well as validating the code for CI. 10 | */ 11 | 12 | /** To work on this script: 13 | rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template 14 | */ 15 | 16 | const fs = require("fs") 17 | const path = require("path") 18 | const { argv } = require("process") 19 | 20 | const projectRoot = argv[2] || path.join(__dirname, "..") 21 | 22 | // Add deps to pkg.json 23 | const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8")) 24 | packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, { 25 | "svelte-check": "^1.0.0", 26 | "svelte-preprocess": "^4.0.0", 27 | "@rollup/plugin-typescript": "^6.0.0", 28 | "typescript": "^3.9.3", 29 | "tslib": "^2.0.0", 30 | "@tsconfig/svelte": "^1.0.0" 31 | }) 32 | 33 | // Add script for checking 34 | packageJSON.scripts = Object.assign(packageJSON.scripts, { 35 | "validate": "svelte-check" 36 | }) 37 | 38 | // Write the package JSON 39 | fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " ")) 40 | 41 | // mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too 42 | const beforeMainJSPath = path.join(projectRoot, "src", "main.js") 43 | const afterMainTSPath = path.join(projectRoot, "src", "main.ts") 44 | fs.renameSync(beforeMainJSPath, afterMainTSPath) 45 | 46 | // Switch the app.svelte file to use TS 47 | const appSveltePath = path.join(projectRoot, "src", "App.svelte") 48 | let appFile = fs.readFileSync(appSveltePath, "utf8") 49 | appFile = appFile.replace("