rslib icon indicating copy to clipboard operation
rslib copied to clipboard

[Feature]: Svelte library support

Open NaviTheCoderboi opened this issue 1 month ago • 4 comments

What problem does this feature solve?

Rslib is an amazing tool but it lacks support for building libraries for svelte, currently we need to have a sveltekit project for building libraries, can't really split it into modules, making it messy

What does the proposed API look like?

A svelte preprocess plugin can be provided, like which preprocesses the .svelte files and emits uncompiled svelte files which is necessary for svelte libraries + a dts plugin for svelte files

Code can be taken from: https://github.com/sveltejs/kit/tree/main/packages/package

NaviTheCoderboi avatar Nov 22 '25 11:11 NaviTheCoderboi

You can use @rsbuild/plugin-svelte to compile svelte files, but we do not provide transform-only mode for svelte now.

Timeless0911 avatar Nov 24 '25 07:11 Timeless0911

our manpower is limited, and we definitely want to support Svelet, whereas this is not our current superior goal. contribution is welcomed if anyone is interested in implementing this feature. and we're glad to help.

fi3ework avatar Nov 24 '25 08:11 fi3ework

our manpower is limited, and we definitely want to support Svelet, whereas this is not our current superior goal. contribution is welcomed if anyone is interested in implementing this feature. and we're glad to help.

I can make a plugin for it, but I need help with that

Like first, I want to preprocess the .svelte file and emit .svelte file, is there possible, how can I do that

Second, svelte files require other way for generating .d.ts files, how do I integrate it with the default rslib dts plugin

NaviTheCoderboi avatar Nov 24 '25 14:11 NaviTheCoderboi

  1. Implement a loader for .svelte file.
  2. I recommend to write a separate plugin to emit svelte dts files, maybe named rsbuild-plugin-svelte-dts.

Timeless0911 avatar Nov 24 '25 15:11 Timeless0911

  1. Implement a loader for .svelte file.

    1. I recommend to write a separate plugin to emit svelte dts files, maybe named rsbuild-plugin-svelte-dts.

i tried this but not worked

import type { RsbuildPlugin } from '@rsbuild/core';

export const pluginSvelteEmit = (): RsbuildPlugin => {
    return {
        name: 'rslib-plugin-svelte',

        setup(api) {
            api.modifyRspackConfig((config, { mergeConfig }) => {
                return mergeConfig(config, {
                    module: {
                        rules: [
                            {
                                test: /\.svelte$/,
                                type: 'asset/resource',
                                parser: {
                                    parse: undefined
                                }
                            }
                        ]
                    },
                    resolve: {
                        extensions: [
                            '.svelte',
                            ...(config.resolve?.extensions || [])
                        ]
                    }
                });
            });
        }
    };
};

export default pluginSvelteEmit;

NaviTheCoderboi avatar Dec 04 '25 12:12 NaviTheCoderboi

I don't think this configuration is necessary, module.parser is an object.

parser: {
    parse: undefined
}

Additionally, I suggest you first clarify the input and output of your svelte file after processing by the loader. assets/resource are similar to file-loader which will not perform any preprocessing on the svelte files.

Timeless0911 avatar Dec 04 '25 13:12 Timeless0911

I don't think this configuration is necessary, module.parser is an object.

parser: {
    parse: undefined
}

Additionally, I suggest you first clarify the input and output of your svelte file after processing by the loader. assets/resource are similar to file-loader which will not perform any preprocessing on the svelte files.

Btw do u have any such plugin for rslib from which I can use for reference?

NaviTheCoderboi avatar Dec 13 '25 05:12 NaviTheCoderboi