svelte-loader icon indicating copy to clipboard operation
svelte-loader copied to clipboard

Use scss in the <style> tag

Open uitcode opened this issue 4 years ago • 5 comments

How can I use scss in style tags of .svelte files?

uitcode avatar Mar 05 '20 04:03 uitcode

@uitcode You need to configure your project's preprocess step: https://svelte.dev/docs#svelte_preprocess

There are some packages that can help you setting up scss to work with svelte:

  • https://github.com/kaisermann/svelte-preprocess
  • https://www.npmjs.com/package/svelte-preprocess-sass

kaisermann avatar Mar 05 '20 14:03 kaisermann

I know it is an aged issue, but I had a similar problem with Typescript and LESS. If you going to use 'svelte-preprocess' you have the possibility to this to support all common preprosseses:

const autoPreprocess =  require('svelte-preprocess');
...
module: {
    rules: [
      ...
      {
        test: /\.(html|svelte)$/,
        exclude: /node_modules/,
        use: {
          loader: 'svelte-loader',
          options: {
            preprocess: autoPreprocess(),
          },
        },
      },
  ...
  ]
}

kulturbande avatar Sep 23 '20 06:09 kulturbande

I wonder if the svelte-loader should accept a string tell it how to import your svelte.config.js instead or whatever file you define your preprocessor in?

Looks like [email protected] doesn't pass over function values in options, so when I debug into svelte-loader autoPreprocess() just ends up with the what appears to be only the serializable values (i.e. defaultLanguages), but no markup, script, and style.

image

JohnnyFun avatar Jul 27 '21 19:07 JohnnyFun

I added this to svelte-loader index.js:

if (options.svelteConfigFileLocation) {
	const svelteConfig = require(options.svelteConfigFileLocation)
	options.preprocess = svelteConfig.preprocess
}

Then modified my webpack to pass svelteConfigFileLocation: path.resolve('../svelte.config.js') instead of preprocess: autoPreprocess().

JohnnyFun avatar Jul 28 '21 00:07 JohnnyFun

@dummdidumm; The original question has been answered so I would recommend closing this issue. Based on the discussion here, it might be worth creating another issue focused on loading a configuration file (svelte.config.js).

mcuppi avatar Jun 06 '22 01:06 mcuppi