question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support svelte.preprocess

See original GitHub issue

Hi there,

since V1.44.0, svelte supports a preprocessing step, e.g. to render scss if used. The API is documented here.

Just an example of what this might look like resp. result in:

const { compile, preprocess } = require('svelte');
const JSAsset = require('parcel-bundler/src/assets/JSAsset');

class SvelteAsset extends JSAsset {
  async parse(code) {
    // preprocess does not do that much
    const preprocessed = await preprocess(code, preprocessOptions);
    const { generatedCode, map, css, cssMap, ast } = compile(preprocessed.toString(), compilerOptions);
    // The other stuff might be useful for different things...

    this.contents = generatedCode;

    return super.parse(this.contents);
  }
}

module.exports = SvelteAsset;

(extracted from the svelte-loader behavior) Supporting this would require to use an external config file that is not in JSON format, since preprocessing requires functions. Maybe something like a .svelte.config.js ? It might be possible to put the general svelte options there as well and only pick the current definition in case the file is absent.

E.g. - .svelte.config.js:

const compilerOptions = { /* compiler options as defined in docs */ };
const preprocessOptions = { /* Preprocess options as defined in docs */ };
module.exports = { compilerOptions, preprocessOptions };

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cdock1029commented, Feb 17, 2020

Link to example is broken… any resource to see how this works?

0reactions
excalibur1987commented, Jun 6, 2020

Link to example is broken… any resource to see how this works?

@cdock1029

The following worked for me.

You need to install a svelte pre-processor plugin to process sass, I used the following plugin

svelte-preprocess-sass

Add a file with the name svelte.config.js to your project root, with the following content to enable sass pre-processing.

const { sass } = require("svelte-preprocess-sass");

module.exports= {
  preprocess: {
    style: sass(),
  },
};

If you want to use it just add type="text/sass" to your style tags inside your svelte components

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub - sveltejs/svelte-preprocess
A Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Pug and much more.
Read more >
Integrations • Docs • SvelteKit
svelte -preprocess has some additional functionality not found in vitePreprocess such as support for Pug, Babel, and global styles.
Read more >
Top 5 svelte-preprocess Code Examples - Snyk
To help you get started, we've selected a few svelte-preprocess examples, based on popular ways it is used in public projects.
Read more >
Writing Your Own Preprocessors - Svelte Society
Svelte's preprocess method expects an object or an array of objects with one or more of markup , script , and style properties,...
Read more >
svelte-preprocess | Yarn - Package Manager
A Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Pug and much more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found