Prerequisites
Before starting the project make sure to install the following utilities:
Creating a new SvelteKit application
Let's create a fresh SvelteKit application so that we can go through all the steps together.
Step 1
Create new project.
SvelteKit
app: App template - Skeleton project
,
Type checking - JS with JSDocs comments
, Additional options -
ESLint
.
Step 2
Run the development server.
Installing and configuring Tailwind CSS and TW Elements
Step 1
Install Tailwind CSS.
File structure
If you have followed all instructions mentioned earlier, your file structure should look like this:
Step 2
Add the paths to all of your template files in your
tailwind.config.js
file.
Step 3
In the svelte.config.js
file, include
vitePreprocess
to enable the handling of
style
blocks as PostCSS.
Step 4
Create app.css
file in src
directory and add the
@tailwind
directives.
Step 5
Create a new file named +layout.svelte
in the
./src/routes
directory and import the recently created
app.css
file.
Step 6
Install TW elements.
Step 7
Import components which are you intend to use and necessary function
initTWE
. Initialize initTWE
in a lifecycle method.
Step 8
Start the app and see if everything's fine. Awesome! You're all set to dive into using TW Elements for your SvelteKit project. Have fun!
Initializing via JS
By default all components have autoinit which means they are initialized by data attributes. But if you want to make init by JavaScript - there is also possibility to do that.
Step 1
Import library and initialize components in lifecycle method.