-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
improve svelte.preprocess docs #3670
Comments
I agree that the documentation could be better on this subject, just to make it more obvious where to put the code at least. To answer your questions though, the So yes, you're correct that it could be used for things like TypeScript support, and in fact, that's what the To set up your own preprocessor in webpack that would be run whilst webpack is watching files, for example, you can just provide your preprocess options to the For example, lets say we hate the colour {
loader: 'svelte-loader',
options: {
css: true,
preprocess: {
style ({ content }) {
// This will replace all instances of the word "red" with "blue" in any styles found in Svelte files
return {
code: content.replace(/red/gi, 'blue')
}
}
}
}
} In this example the |
Thanks! I was able to get your example to work using Rollup. Now I'd like to want to enable use of Sass and TypeScript (with limitations). import { scss, postcss } from 'svelte-preprocess'
svelte.preprocess(input, [
scss(),
postcss({
plugins: [
require('autoprefixer')({
browsers: 'last 2 versions',
}),
],
}),
]) But I thought the second argument to |
The second argument to If it's an array then it will loop through each preprocessor in order passing the output of the previous one to the next. As for SASS I'm not sure why it won't work for you. I don't use it myself so I've never configured it before. |
I forgot to mention that I'm using Sapper. Here are the relevant parts of my import sveltePreprocess from 'svelte-preprocess';
...
const preprocess = sveltePreprocess({
sass: true,
typescript: true
});
export default {
client: {
...
plugins: [
...
svelte({
...
preprocess
}),
...
},
server: {
...
plugins: [
...
svelte({
...
preprocess
}),
...
],
...
},
...
}
}; |
This is mostly working for me know using the configuration I showed above. However, it seems that TypeScript doesn't know what do with |
That doesn't have anything to do with the |
The documentation on
svelte.preprocess
at https://svelte.dev/docs#svelte_preprocess shows some code examples to configure it. But it doesn't provide the expected name and location of those files. Is this just Node code that can be in any.js
file and must be run manually? Is there a way forsvelte.preprocess
to be run automatically as part of the normal watch/live-reload cycle?IIUC, this can be used to enable use of TypeScript inside
<script>
tags, perhaps with some limitations to be addressed in the future. It would be great to show an example of how to configure that!The text was updated successfully, but these errors were encountered: