Support svelte.preprocess
See original GitHub issueHi 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:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.If you want to use it just add
type="text/sass"
to your style tags inside your svelte components