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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@paulio/auto-import-svelte

v0.1.2

Published

P72: Auto import Svelte components

Downloads

404

Readme

Made to be Plundered Latest version Release date

P72: Auto-Import Svelte

Simple Svelte preprocessor for auto importing sets of components.

This library is a scaffolding tool to minimise boiler plate as a source of programming friction during development. $autoImport statements can be replaced with explicit imports at any time.

<script>
	// Specific directory import.
	$autoImportDir('.')

	// Glob import.
	$autoImportGlob('../shared/**/*')

	// Auto imports support SvelteKit `$lib` alias.
	$autoImportDir('$lib/charts')

	// Auto imports support `$root` alias.
	$autoImportDir('$root/src')
</script>

Very simple and lazy implementation:

  • It will only import components used within the HTML section of Svelte components, i.e. not those created dynamically.
  • It won't check if a component is already imported, thus, will cause a compile error if imported manually.
  • It doesn't work for library imports or absolute paths, relatively referenceable components only.
  • Auto import statements must be on a single line and the path must be a single or double quoted string literal.

Good Usage

package.json

{
	"devDependencies": {
		"@paulio/auto-import-svelte": "0.1.2"
	}
}

svelte.config.js

<script>
	// svelte.config.js
	import autoImportSvelte from 'auto-import-svelte'

	export default {
		preprocess: [autoImportSvelte()],
	}
</script>

Component.svelte

Auto import paths may be relative to either:

  • ./, ../blah, etc: The importing component's parent directory.
  • $lib/: referencing ./src/lib (SvelteKit).
  • $root/: referencing the project's root directory.
<script>
	// Import all used components from this component's
	// parent directory.
	$autoImportDir('.')

	// From a sub directory.
	$autoImportDir('./sub-folder')

	// From a sibling directory.
	$autoImportDir('../sibling-directory')

	// From `{root}/src/lib/components`.
	$autoImportDir("$lib/components")

	// From `{root}/pkg`.
	$autoImportDir("$root/pkg")

	// Import all used components from `{root}/src/lib` and
	// its sub directories.
	//
	// See https://www.npmjs.com/package/glob for more info.
	$autoImportGlob("$lib/**/*")
</script>

Bad Usage

<script>
	// Manual imports must be removed or face a conflicting
	// import error.
	import Component from './Component.svelte'
	$autoImportDir('.')

	// Not allowed library imports.
	$autoImportDir('flowbite-svelte')

	// Not allowed absolute path.
	$autoImportDir('/absolute/path/to/dir')

	// Multiline auto imports not allowed.
	$autoImportDir(
		'.',
	)
</script>

Sorry, just CBA to do proper parsing for this project. However, the limitations haven't been an issue given my development style.

Made to be Plundered

Alternatively, Copy & paste files from /src into your project. Tests are written in Jest but should be easy to adapt or rewrite for whatever testing framework.