@svelte-put/preprocess-external-link
v2.0.0
Published
add attributes to external links at compile-time
Maintainers
Readme
@svelte-put/preprocess-external-link
Vite plugin / Svelte preprocessor to add appropriate attributes to external links at compile-time.
svelte-put
This package is part of the @svelte-put family. For contributing guideline and more, refer to its readme.
Usage & Documentation
See the dedicated documentation page here.
Example
Given the following Vite config...
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { externalLink } from '@svelte-put/preprocess-external-link'; // [!code ++]
export default defineConfig({
plugins: [
svelte(), // or import('@sveltejs/kit/vite').sveltekit
externalLink(['your-domain.com', 'your-other-domain.com']), // [!code ++]
],
});...and the following source code...
<script>
let href = 'https://developer.mozilla.org';
</script>
<!-- links that are treated as internal -->
<a href="/internal-path">Internal Path</a>
<a href="https//your-domain.com/some-path">Internal Path</a>
<a href="https//your-other-domain.com/some-path">Internal Path</a>
<!-- links that are treated as external, implicitly -->
<a href="https://svelte.dev/">Svelte</a>
<!-- links that are treated as external, explicitly by specifying data-external -->
<a {href} data-external>Svelte</a>...preprocess-external-link will generate the following intermediate Svelte output:
<script>
let href = 'https://developer.mozilla.org';
</script>
<!-- links that are treated as internal -->
<a href="/internal-path">Internal Path</a>
<a href="https//your-domain.com/some-path">Internal Path</a>
<a href="https//your-other-domain.com/some-path">Internal Path</a>
<!-- links that are treated as external, implicitly -->
<a href="https://svelte.dev/" target="_blank" rel="noreferrer noopener">Svelte</a>
<!-- links that are treated as external, explicitly by specifying data-external -->
<a {href} data-external target="_blank" rel="noreferrer noopener">Svelte</a>