npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

npdev-svelte-loadable-babel

v1.0.0

Published

The babel plugin for use with `svelte-loadable` and/or `npdev:svelte-loadable` (for Meteor)

Downloads

5

Readme

npdev-svelte-loadable-babel

Works with svelte-loadable (and npdev:svelte-loadable) to make code splitting a breeze!

Usage

A resolve function is necessary for the cache to keep track of its loaded assets, and for SSR solutions. The resolve function must return a resolved path, which will be used to keep track of loadables, and to facilitate loading before hydration in SSR solutions. This babel plugin can help automated the inclusion of the resolve function. See the svelte-loadable readme to learn more about how to register your Loadables.

The following is an example set of Loadables without using npdev-svelte-loadable-babel:

App.svelte:

<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'),
  resolve: () => require.resolve('./pages/Page.svelte')
})
const HomeLoader = register({
  loader: () => import('./home/Home.svelte'),
  resolve: () => require.resolve('./home/Home.svelte')
})
</script>

<script>
import { Router, Link, Route } from 'svelte-routing'
import Loadable from 'svelte-loadable'

export let url = ''
</script>

<Router url="{url}">
  <Route path="/pages/:slug" let:params>
    <Loadable loader={PageLoader} slug={params.slug}>
      <div slot="loading">Loading...</div>
    </Loadable>
  </Route>
  <Route path="/">
    <Loadable loader={HomeLoader} />
  </Route>
</Router>

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": [
    "npdev-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>

The 'svelte-loadable-capture' Context for SSR

To facilitate the creation of SSR solutions, Svelte Loadable uses a context which can be set up in a LoadableProvider using the string identifier 'svelte-loadable-capture'. Svelte Loadable expects the context to provide a method, to which it will pass the registered loader function. For an example implementation, check out npdev:svelte-loadable built on Meteor and Svelte Loadable.

Additional notes about Meteor and WebPack

This babel plugin is useful for anyone implementing svelte-loadable (or npdev:svelte-loadable for Meteor) to cut down on a bit of extra typing and repetition, but it was originally meant to be a complete SSR solution for Meteor. Nothing else is needed for SSR in Meteor (all Meteor needs is the resolve method - tehcnically, we don't even need this convenient babel plugin).

For anyone interested in creating a similar WebPack solution, you may need to add an additional parameter in addition to the resolve method, to associate the right bundle per Loadable. Checkout react-loadable's original implementation for more.