-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preprocessor support #8
Comments
Copying a piece of a conversation from chat from last month, so it has a more permanent home:
|
What's the process that's happening when we use the process feature? Does Svelte transpiles the component into a preprocessors-free component before compiling it or compiles it directly? |
Yeah. |
The bundler plugins call |
So couldn't we just add an |
|
To make this simpler, I think it might be a good idea to make the |
ay yo, i found a way we could use svelte.preprocess to spit out vanilla .svelte files for consumers that do not use a specific preprocessor. its not much right now but could be a stepping stone? forgive the code formatting, i am using prettier 2.1.0 and it isn't playing well with svelte right now. sample compile script import { preprocess } from 'svelte/compiler';
import autoprocessor from 'svelte-preprocess';
import * as fs from 'fs';
const doStuff = async () => {
const source = fs.readFileSync(
`${__dirname}/src/Button/Button.svelte`,
'utf-8'
);
await preprocess(source, autoprocessor(), { filename: 'Button.svelte' })
.then((item) => {
console.log('Svelte Code: ', item.code);
fs.mkdirSync(`${__dirname}/dist/Button/`, {
recursive: true,
});
fs.writeFileSync(`${__dirname}/dist/Button/Button.svelte`, item.code);
})
.catch((error) => {
console.error(error.message);
});
};
doStuff(); src svelte <script lang="ts">
export let text = '';
export let rounded: boolean = false;
export let circle: boolean = false;
let buttonElement: HTMLElement;
let spanElement: HTMLElement;
let mouseX: number;
let mouseY: number;
function clickEvent(e: MouseEvent) {
var { left, top } = buttonElement.getBoundingClientRect();
mouseX = e.clientX - left;
mouseY = e.clientY - top;
spanElement.style.left = `${mouseX}px`;
spanElement.style.top = `${mouseY}px`;
}
</script>
<style lang="scss">
button {
position: relative;
overflow: hidden;
padding: 8px 16px;
border: solid thin black;
background-color: inherit;
color: black;
cursor: pointer;
font-size: inherit;
outline: none;
transition: all 0.3s;
&:hover {
background-color: lightgrey;
}
& > span {
position: absolute;
display: none;
width: 100px;
height: 100px;
margin-top: -50px;
margin-left: -50px;
animation: ripple 1s;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 50%;
content: '';
opacity: 0;
transition: background-color 0.3s;
}
&:focus:not(:active) span {
display: block;
}
}
@keyframes ripple {
from {
opacity: 1;
transform: scale(0);
}
to {
opacity: 0;
transform: scale(10);
}
}
.rounded {
border-radius: 5px;
}
.circle {
padding: 8px;
border-radius: 50%;
}
</style>
<template>
<button
class:rounded
class:circle
on:click={clickEvent}
bind:this={buttonElement}>
<slot />
{text}
<span class="active" bind:this={spanElement} />
</button>
</template>
dist svelte <script>
export let text = '';
export let rounded = false;
export let circle = false;
let buttonElement;
let spanElement;
let mouseX;
let mouseY;
function clickEvent(e) {
var { left, top } = buttonElement.getBoundingClientRect();
mouseX = e.clientX - left;
mouseY = e.clientY - top;
spanElement.style.left = `${mouseX}px`;
spanElement.style.top = `${mouseY}px`;
}
</script>
<style>
button {
position: relative;
overflow: hidden;
padding: 8px 16px;
border: solid thin black;
background-color: inherit;
color: black;
cursor: pointer;
font-size: inherit;
outline: none;
transition: all 0.3s; }
button:hover {
background-color: lightgrey; }
button > span {
position: absolute;
display: none;
width: 100px;
height: 100px;
margin-top: -50px;
margin-left: -50px;
animation: ripple 1s;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 50%;
content: '';
opacity: 0;
transition: background-color 0.3s; }
button:focus:not(:active) span {
display: block; }
@keyframes ripple {
from {
opacity: 1;
transform: scale(0); }
to {
opacity: 0;
transform: scale(10); } }
.rounded {
border-radius: 5px; }
.circle {
padding: 8px;
border-radius: 50%; }
</style>
<button
class:rounded
class:circle
on:click={clickEvent}
bind:this={buttonElement}>
<slot />
{text}
<span class="active" bind:this={spanElement} />
</button>
|
I am using <style lang="scss" global>
@use "./Alert.scss";
</style>
I solved this problem using process.chdir |
Any news on this? I have a Svelte component where I use SASS, and I would like to prevent consumers from having to configure SASS themselves. So ideally, I would like to publish my component in such a way that SASS is already preprocessed. I tried the proof of concept posted by @BlackFenix2 in #8 (comment) which looks like it should do the trick, but can't get that working for SASS unfortunately. |
The planned way forward with this is sveltejs/kit#518 which will replace this whole template repo and will also handle preprocessors. |
Thanks @Conduitry for your fast response, I actually commented there some time ago 😁. Makes sense to focus effort on SvelteKit, I'm really looking forward to that. I started using Svelte not that long ago, and right now I feel like I'm in no man's land - just trying to get something working for the time being. |
Closing in favour of focusing on |
If someone wants to publish a component that they've written that needs preprocessors, what they should be publishing is
main
/module
pointing at a completely compiled version (like now), butsvelte
should point to the preprocesed component(s), not their original source. I'm not sure what the best way to do this is.The text was updated successfully, but these errors were encountered: