svelte-tailwindcss-template Svelte Themes

Svelte Tailwindcss Template

svelte tailwindcss app

This is a project template for Svelte & TailwindCSS apps. It lives at https://github.com/DariusCorvus/svelte-tailwindcss-template.

To create a new project based on this template using degit:

npx degit dariuscorvus/svelte-tailwindcss-template svelte-tailwindcss-app
cd svelte-tailwindcss-app

Note that you will need to have Node.js installed.

Get started

Install the dependencies...

cd svelte-tailwindcss-app
npm install

...then start Rollup:

npm run dev

Navigate to localhost:5000. You should see your app running. Edit a component file in src, save it, and reload the page to see your changes.

If you're using Visual Studio Code we recommend installing the official extension Svelte for VS Code. If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense.

Building and running in production mode

To create an optimised version of the app:

npm run build

You can run the newly built app with npm run start. This uses sirv, which is included in your package.json's dependencies.


Adjustments that were needed

Configure plugins

TailwindCSS and AutoPrefixer plugin were added in the rollup.config.js file.

///...
import sveltePreprocess from 'svelte-preprocess';
///...
export default {
    //...
    plugins: [
        svelte({
            //...
            preprocess: sveltePreprocess({
                sourceMap: !production,
                postcss: {
                    plugins: [require('tailwindcss'), require('autoprefixer')]
                }
            })
        }),
        //...
    ],
    //...
};

Configurated the tailwind.config.js file.

module.exports = {
    mode: "jit", // JIT stands for Just in Time Compiler and makes the Build and the Startup so fast.
                // at the moment JIT is just in the preview but works like a charme.
    purge: ['./public/index.html', './src/**/*.svelte'],
    //...
}

Apply TailwindCSS

Created TailwindCSS.svelte file in the src directory.

<style global lang="postcss">
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
</style>

And added the import in the main svelte file 'App.svelte' to apply TailwindCSS project wide.

<script>
    import TailwindCss from "./TailwindCSS.svelte";
</script>

Top categories

Loading Svelte Themes