This is a project template for Svelte, TypeScript & TailwindCSS apps. It lives at https://github.com/DariusCorvus/svelte-typescript-tailwindcss-template.
To create a new project based on this template using degit:
npx degit dariuscorvus/svelte-typescript-tailwindcss-template svelte-typescript-tailwindcss-app
cd svelte-typescript-tailwindcss-app
Note that you will need to have Node.js installed.
Install the dependencies...
cd svelte-typescript-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 you can see the 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.
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
.
TailwindCSS and AutoPrefixer plugin were added in the
rollup.config.js
file.
///...
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'],
//...
}
Created
TailwindCSS.svelte
file in thesrc
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 lang="ts">
import TailwindCss from "./TailwindCSS.svelte";
//...
</script>