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.

Add Ability to Configure Svelte-Loader Options

See original GitHub issue

I love storybook, but I can’t use it with my Svelte components because I’m using a stylus preprocessor with my components and (as far as I can tell) there’s no way for me to tell storybook about my preprocessor.

What I need is a way to pass options into framework-preset-svelte.js at line 11

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rixocommented, Aug 7, 2019

@shilman Not at all. But AFAIK, @amwmedia’s solution is the correct way. I would have done it this way.

With my proposed changes in their current form, it should also keep working as it is. But that’s more luck than anything else; I experimented with changing this rule at a point, to make it work.

Maybe that would be nice to be able to expose some particularly interesting rules / loaders / loader options to users, to spare them the need to do this fragile lookup themselves, but that would be a feature from SB core (and it might be tricky to do it right).

What I can do is add a comment in Svelte’s framework presets to remind anyone that this signature (first level rule with a loader prop containing 'svelte-loader') should be preserved or considered a breaking change.

@amwmedia To be safe (well… safer), you should probably preserve existing loader options though.

svelteLoader.options = {
  ...svelteLoader.options,
  preprocess: { ... },
}

(Or you can directly modify the config arg that your are provided, it is intended for that.)

I think it’s safe to assume that preprocess will never be used by SB, so it’s safe to overwrite it. As long as you ensure that your custom preprocessor preserves support for raw syntaxes (i.e. CSS in your case).

1reaction
shilmancommented, Jul 17, 2019

@amwmedia AFAIK there is no easy way to do that. However, as a workaround you can configure webpack manually by removing the rule in question, and adding a replacement that has the options you need. Or, if you’re feeling cavalier, just updating the existing rule in place. See https://storybook.js.org/docs/configurations/custom-webpack-config/#full-control-mode

Read more comments on GitHub >

github_iconTop Results From Across the Web

svelte-loader - npm
A webpack loader for svelte. ... Start using svelte-loader in your project by running `npm i svelte-loader` ... Install. npm i svelte-loader ......
Read more >
Working with Webpack | Svelte CLI - GitHub Pages
Some webpack options are set based on values in svelte.config.js and ... raw webpack config, with the ability to define named loader rules ......
Read more >
Adding TypeScript to an existing Svelte project - LogRocket Blog
Add TypeScript to an existing Svelte project using a web application bundler like Parcel, Rollup, or webpack.
Read more >
Learn Svelte
Every Svelte component instance has a small number of methods you can use to control it, in addition to any custom methods you...
Read more >
How to setup custom elements with svelte + rails/webpacker
I've been trying to setup svelte custom elements with webpacker. This is loaders/svelte.js module.exports = { test: /\.svelte$/, ...
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