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

Provide a vite plugin for optimising imports #33

Open
MathiasWP opened this issue Jul 3, 2023 · 0 comments
Open

Provide a vite plugin for optimising imports #33

MathiasWP opened this issue Jul 3, 2023 · 0 comments

Comments

@MathiasWP
Copy link

MathiasWP commented Jul 3, 2023

It's recommended to do direct imports to avoid slow a slow dev-experience, but doing bare imports is so much nicer.

Suggested feature:

Export a vite plugin that optimises imports from this library.

// vite.config.ts
import { sveltekit } from '@sveltejs/kit/vite';
import { iconImportOptimiser } from 'svelte-bootstrap-icons/vite';

export default defineConfig(() => {
	return {
		plugins: [
			sveltekit(),
			iconImportOptimiser(),
		]
	};
});

The plugin would apply the following transformation to svelte and typescript files:

From

  // my-file.js/ts
  import { Alarm, Bank, CloudMoon } from "svelte-bootstrap-icons";
<script>
  // MyComponent.svelte
  import { Alarm, Bank, CloudMoon } from "svelte-bootstrap-icons";
</script>

To

  // my-file.js/ts
  import Alarm from "svelte-bootstrap-icons/lib/Alarm.svelte";
  import Bank from "svelte-bootstrap-icons/lib/Bank.svelte";
  import CloudMoon from "svelte-bootstrap-icons/lib/CloudMoon.svelte";
<script>
  // MyComponent.svelte
  import Alarm from "svelte-bootstrap-icons/lib/Alarm.svelte";
  import Bank from "svelte-bootstrap-icons/lib/Bank.svelte";
  import CloudMoon from "svelte-bootstrap-icons/lib/CloudMoon.svelte";
</script>

Tip:

https://github.com/guybedford/es-module-lexer is a super-fast library for detecting imports (if vite does not provide a simple API for getting them)

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

No branches or pull requests

1 participant