kaisermann / svelte-loadable

Dynamically load a svelte component
MIT License
322 stars 13 forks source link

Add the babel-plugin with configuration notes in the readme #16

Closed CaptainN closed 4 years ago

CaptainN commented 5 years ago

Thanks for merging all the stuff I've been throwing at you! I appreciate it. This should really be the last addition. The only other thing I'd like to add is maybe some porting notes for anyone who wants to pick up a port to WebPack. Other than that, this should be it!

This PR adds a babel plugin, which can be configured to automatically add the resolve method to registered loaders (less boilerplate - yay!). As explained in the readme:

babel plugin

The Svelte Loadable babel plugin will automatically add the resolve method to your registered loaders, to cut down on manual configuration. Add the Svelte Loadable babel plugin to your plugins list in .babelrc or equivalent:

.babelrc or package.json

{
  "plugins": [
    "svelte-loadable/babel"
  ]
}

Once configured, you can skip adding the resolve method, and let the babel plugin do it for you:

<script context="module">
import { register } from 'svelte-loadable'

// Loaders must be registered outside of the render tree.
const PageLoader = register({
  loader: () => import('./pages/Page.svelte')
})
const HomeLoader = register({
  loader: () => import('./home/Home.svelte')
})
</script>
CaptainN commented 5 years ago

For npdev:react-loadable I released a separate npm package for the accompanying babel plugin. Do you think that would make sense in this case as well? If so, feel free to close this PR, and I'll do it that way.

kaisermann commented 5 years ago

Oooh, I still haven't had the time to look into this PR 😁

In advance, I think it makes sense for the plugin to be alongside the component itself (it's a small piece of code)

CaptainN commented 5 years ago

Awesome! I'll keep waiting then, no rush!

CaptainN commented 4 years ago

Any progress? :-)

kaisermann commented 4 years ago

Oh, sorry! Completely forgot about this one. Will tackle this after the refactor I'm doing in svelte-i18n 😁

CaptainN commented 4 years ago

Any chance to look at this? I can probably do this as a separate release on npm. It might make sense to do that anyway, since this is fairly specific to Meteor. Other bundlers like WebPack likely require additional information that this babel plugin does not provide.

kaisermann commented 4 years ago

Hey @CaptainN, my mistake, I've completely forgot about your PR, sorry 😞 . I think having a separate package would be the best way to go, less payload for people who doesn't need it.

CaptainN commented 4 years ago

Okay cool. I'll do that then, and maybe submit a simple mention about it in the Readme (I'll make a smaller PR for that)? It might also point someone in the right direction who might like to implement a version for WebPack.