-
-
Notifications
You must be signed in to change notification settings - Fork 432
How to add Sass Support #123
Comments
Hi @vladejs! Have you stumbled upon this repository? It might give some inspiration. |
I saw it uses rollup. Sapper uses webpack. I don't quite understand how to achieve it |
Take the Be aware of this issue! At some point that |
Thanks. I made it work. That way I dont clutter the config with custom functions and can have the preprocess logic in its own file. btw I'm enjoying using svelte. Hope it evolves in popularity as well as react did. |
Do you know how to use svelte with meteor? I know there is a package for it but don't know how to do routing. I'm also interested in using sapper with meteor as backend only. It could be the perfect stack for me. Thanks |
@vladejs do you have a code sample of this working you can share? |
@vladejs +1 to that. Please let us know when you have an example =) |
I'll close this as there's no action required; SASS support is achievable with |
@vladejs @Rich-Harris |
hey @DanielSokil take a look to webpack/client.config.js and webpack/server.config.js |
Hi, I'm sorry to resurface an old ticket, but now that a year has passed, how do you get this to work with the sapper-template? I've tried the following: import sass from 'node-sass';
...
...
...
svelte({
dev,
hydratable: true,
emitCss: true,
css: css => {
css.write('public/bundle.css');
},
preprocess: {
style: ({ content, attributes }) => {
if (attributes.type !== 'text/scss') return;
return new Promise((fulfill, reject) => {
sass.render({
data: content,
includePaths: ['./node_modules', 'src'],
sourceMap: true,
outFile: 'x'
}, (err, result) => {
if (err) return reject(err);
fulfill({
code: result.css.toString(),
map: result.map.toString(),
});
});
});
}
}
}), When I run
I'm not sure how to debug this really. I'd step through the rollup code with a debugger, if I knew how. I tried searching for occurrences of the errant code, and I found these. There's only one occurrence of $ ag -S -u mappings.charCodeAt -o
node_modules/magic-string/dist/magic-string.umd.js.map
1:mappings.charCodeAt
node_modules/rollup/dist/rollup.js
596:mappings.charCodeAt
node_modules/rollup/dist/rollup.es.js
588:mappings.charCodeAt
node_modules/sourcemap-codec/dist/sourcemap-codec.es.js
16:mappings.charCodeAt
node_modules/sourcemap-codec/dist/sourcemap-codec.umd.js
22:mappings.charCodeAt What might I be doing wrong? Thanks! |
Just use svelte-preprocess-sass In import { sass } from "svelte-preprocess-sass";
// Add preprocess to svelte plugin in `client` and `server`
// Client:
svelte({
dev,
hydratable: true,
emitCss: true,
preprocess: {
style: sass()
}
}),
// Server
svelte({
generate: "ssr",
dev,
preprocess: {
style: sass()
}
}), In your components, use it as: <style type="text/sass">
$font-stack: Helvetica, sans-serif;
$primary-color: red;
p {
font: $font-stack;
color: $primary-color;
}
</style> |
@s0kil - Thanks. I'd tried using that to begin with, but I think I was doing a number of things slightly incorrect, so I wasn't seeing results. Your example painted it clear as day for me, and I was able to import an scss module. |
This works but how would someone include bulma.sass globaly... |
@imsamtar There is not yet a solid solution to make such thing happen. But you could import it in every component. |
A Sass example for both
module: {
rules: [
{
test: /\.svelte$/,
use: {
loader: 'svelte-loader',
options: {
emitCss: true,
hotReload: true,
preprocess: [
{
style: sassToCSS
}
],
},
},
},
plugins: [
svelte({
preprocess: [
{
style: sassToCSS,
},
], where |
So, if I understand correctly, the current way to say import global sass variables is to import that file in each component? I'm fine with that, just looking for clarification. |
At what point did the author ask for a rollup solution? |
@badunius — can you clarify what you mean? |
It's just my second day of looking for a way to integrate sass with sapper/svelte, and I always stumble upon rollup solutions, despite the fact that sapper comes with webpack. To quote Red Dwarf, "There are problems in that can't be solved by rollup". And even this one (#123 (comment)) produces a compilation error (unexpected token) |
For those who want to integrate sass with sapper/svelte and webpack, have you checked out svelte-preprocess? It's working for me. |
I ended up using https://medium.com/@sean_27490/svelte-sapper-with-sass-271fff662da9 I created this minimal template: https://github.com/PierBover/svelte-sapper-starter-kit-minimal-rollup |
For those wanting a fork of the base sapper-template with SASS enabled, I've created this repo here: https://github.com/lucianoratamero/sapper-sass-template You may create your project based on it by running Since I created it for personal use, I added a few opinionated configuration files for editorconfig, eslint, nvm and prettier, though. |
I want to add sass support to the single component style tag.
The text was updated successfully, but these errors were encountered: