Skip to content
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

Plugins #194

Closed
nsaunders opened this issue Dec 13, 2016 · 8 comments
Closed

Plugins #194

nsaunders opened this issue Dec 13, 2016 · 8 comments

Comments

@nsaunders
Copy link

I see that there is a "Plugins" section in the Svelte guide, but I'm not sure whether that refers to the plugins for Webpack, Rollup, Metalsmith, et cetera; or implies that we will be able to write plugins that extend the Svelte compiler in the future. Hopefully the latter!

@Rich-Harris
Copy link
Member

It refers to runtime plugins that extend Svelte with things like custom event handlers and, when we get round to implementing them, transitions.

But extending the compiler is an interesting concept – maybe we could create plugins that (for example) baked Redux support into components, rather than having to add glue code.

The API for building loader plugins is very small, and is documented on the README.

@dschulten
Copy link

Or allow to have css precompilers for component styles. Great, I'll have a look into the readme.

@dschulten
Copy link

I have looked into the README and I do not see an API for building loader plugins there, or at least not what I hoped to find. What do you mean by loader plugins, plugins to the svelte-cli?

@dschulten
Copy link

Possible extension points might be parse/read/script/style.js and parse/read/script.js - the extension point could allow to redefine them with functions that take the same arguments (parser, start, attributes) but can process the content, e.g. based on the style rel or script type attribute. Would that be a good way to go about this?

@Rich-Harris
Copy link
Member

Loader plugins refers to things like rollup-plugin-svelte and svelte-loader — i.e. integrations with existing build tools that makes it easy to use Svelte in your app.

CSS precompilers would presumably be handled as a compiler option — if it was implemented it would probably look something like this:

const { code, map } = svelte.compile( source, {
  preprocess: {
    less ( code ) {
      // some code happens
      return { code, map };
    },
    coffeescript ( code ) {
      // some code happens
      return { code, map };
    }
  }
});

Then templates would have <style type='less'> or <script type='coffeescript'> or whatever. But those features are tracked at #181 (gah, just seen you commented there at about the same time!) and #98.

@nsaunders
Copy link
Author

nsaunders commented Jan 4, 2017

@Rich-Harris, just a reminder (in case you missed my comment in #181 in particular) that LESS compilation is asynchronous to my knowledge, and I would bet it isn't the only preprocessor like that. Therefore, I think that svelte.compile itself should be made async in version 2, even if we don't get around to adding plugin support right away. (Then, when we do add it, it won't be a breaking API change.) Otherwise, I like the preprocess API you suggested.

@PaulBGD
Copy link
Member

PaulBGD commented Feb 12, 2017

@therealnicksaunders That's a really good point, svelte.compile should return a promise or accept a callback. How should we make that breaking change? We could provide another method like svelte.compileAsync then disallow any async processors/plugins in svelte.compile.

@Rich-Harris
Copy link
Member

This can be closed, since we now have svelte.preprocess for handling things like LESS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants