DEV Community

AW A RE
AW A RE

Posted on

11 2

How to use scss with Svelte?

It might sound a simple question but it took me enough time to almost get frustrated learning svelte. It is simple, but documantations are not simple. So I wanted to walk through this process.

Table of Contents

Svelte Installation

npx degit sveltejs/template my-svelte-project

npm install

npm run dev

Svelte Preprocess

npm install -D svelte-preprocess

After installation,
1)import svelte-preprocess in rollup.config.js.
2)add preprocess: sveltePreprocess()
-source for svelte preprocess

import svelte from 'rollup-plugin-svelte'
+ import sveltePreprocess from 'svelte-preprocess';

export default {
  ...
  plugins: [
    svelte({
+     preprocess: sveltePreprocess(),
      // enable run-time checks when not in production
      dev: !production,
      // we'll extract any component CSS out into
      // a separate file — better for performance
      css: css => {
        css.write('public/bundle.css')
      },
    }),
  ],
}
Enter fullscreen mode Exit fullscreen mode

Sass

npm install -D sass

-source for this step

<style type="text/scss">
   @import "./styles.scss";
</style>
Enter fullscreen mode Exit fullscreen mode

OR

<style lang="scss">
    ...
</style>
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (5)

Collapse
 
souksyp profile image
Souk Syp.

Very nice !
For VS Code users, you'll get an error cannot find module sass node-sass.
The solution : daveceddia.com/svelte-with-sass-in...

Collapse
 
conspirisi profile image
conspirisi

Just scoping out the potential for Sass with Svelte. Does live preview with sass work ok?

Collapse
 
algaly profile image
Avraham • Edited

Worked perfectly for me,
pay attention

Collapse
 
sikandar profile image
Sikandar Bhide

Easiest way to Add Svelte with scss
github.com/SikandarJODD/Svelte-Js-...

Collapse
 
sikandar profile image
Sikandar Bhide

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay