diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3db96217..7dd449b7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1415,6 +1415,66 @@ importers: specifier: ^5.9.3 version: 5.9.3 + rslib/svelte-basic: + devDependencies: + '@rsbuild/plugin-svelte': + specifier: ^1.1.1 + version: 1.1.1(@babel/core@7.29.0)(@rsbuild/core@2.0.6)(less@4.6.4)(postcss-load-config@6.0.1)(postcss@8.5.14)(pug@3.0.2)(sass@1.99.0)(stylus@0.64.0)(svelte@5.55.7)(typescript@5.9.3) + '@rslib/core': + specifier: ^0.21.5 + version: 0.21.5(@module-federation/runtime-tools@2.4.0)(core-js@3.49.0)(typescript@5.9.3) + '@tsconfig/svelte': + specifier: ^5.0.8 + version: 5.0.8 + '@types/node': + specifier: ^24.12.4 + version: 24.12.4 + svelte: + specifier: ^5.55.5 + version: 5.55.7(@typescript-eslint/types@8.59.3) + svelte-check: + specifier: ^4.4.8 + version: 4.4.8(picomatch@4.0.4)(svelte@5.55.7)(typescript@5.9.3) + svelte-preprocess: + specifier: ^6.0.3 + version: 6.0.3(@babel/core@7.29.0)(less@4.6.4)(postcss-load-config@6.0.1)(postcss@8.5.14)(pug@3.0.2)(sass@1.99.0)(stylus@0.64.0)(svelte@5.55.7)(typescript@5.9.3) + svelte2tsx: + specifier: ^0.7.55 + version: 0.7.55(svelte@5.55.7)(typescript@5.9.3) + typescript: + specifier: ^5.9.3 + version: 5.9.3 + + rslib/svelte-bundleless: + devDependencies: + '@rsbuild/plugin-svelte': + specifier: ^1.1.1 + version: 1.1.1(@babel/core@7.29.0)(@rsbuild/core@2.0.6)(less@4.6.4)(postcss-load-config@6.0.1)(postcss@8.5.14)(pug@3.0.2)(sass@1.99.0)(stylus@0.64.0)(svelte@5.55.7)(typescript@5.9.3) + '@rslib/core': + specifier: ^0.21.5 + version: 0.21.5(@module-federation/runtime-tools@2.4.0)(core-js@3.49.0)(typescript@5.9.3) + '@tsconfig/svelte': + specifier: ^5.0.8 + version: 5.0.8 + '@types/node': + specifier: ^24.12.4 + version: 24.12.4 + svelte: + specifier: ^5.55.5 + version: 5.55.7(@typescript-eslint/types@8.59.3) + svelte-check: + specifier: ^4.4.8 + version: 4.4.8(picomatch@4.0.4)(svelte@5.55.7)(typescript@5.9.3) + svelte-preprocess: + specifier: ^6.0.3 + version: 6.0.3(@babel/core@7.29.0)(less@4.6.4)(postcss-load-config@6.0.1)(postcss@8.5.14)(pug@3.0.2)(sass@1.99.0)(stylus@0.64.0)(svelte@5.55.7)(typescript@5.9.3) + svelte2tsx: + specifier: ^0.7.55 + version: 0.7.55(svelte@5.55.7)(typescript@5.9.3) + typescript: + specifier: ^5.9.3 + version: 5.9.3 + rslib/umd: devDependencies: '@rsbuild/plugin-react': @@ -9788,6 +9848,9 @@ packages: resolution: {integrity: sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==} engines: {node: '>=10'} + dedent-js@1.0.1: + resolution: {integrity: sha512-OUepMozQULMLUmhxS95Vudo0jb0UchLimi3+pQ2plj61Fcy8axbP9hbiD4Sz6DPqn6XG3kfmziVfQ1rSys5AJQ==} + dedent@0.7.0: resolution: {integrity: sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA==} @@ -14377,6 +14440,12 @@ packages: typescript: optional: true + svelte2tsx@0.7.55: + resolution: {integrity: sha512-JWzgeM3lqySRNfqcsesvVEh8LhTWBxQJ9RMjzJ+VepdmXtVnNd0SbtGctG6+/fbHq0N6mhwSd823gszw9JHeGQ==} + peerDependencies: + svelte: ^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0 + typescript: ^4.9.4 || ^5.0.0 || ^6.0.0 + svelte@5.55.7: resolution: {integrity: sha512-ymI5ykLPwIHW839E053FQbI1G+jnRFJEw3Kv5Y4njixVWywQBx+NUFpkkKyk5LIb36Fg9DVXSYpqiGekLD0hyw==} engines: {node: '>=18'} @@ -15088,8 +15157,8 @@ packages: vue-component-type-helpers@3.2.8: resolution: {integrity: sha512-9689efAXhN/EV86plgkL/XFiJSXhGtWPG6JDboZ+QnjlUWUUQrQ0ILKQtw4iQsuwIwu5k6Aw+JnehDe7161e7A==} - vue-component-type-helpers@3.2.9: - resolution: {integrity: sha512-S3BiWYaLSzHxTpln665ELSrMR9UYmrIDUmhik7nVZxmJjTKL2/a+ew1hvGxksKelivm0ujjWfG1fYOiU/2e8rA==} + vue-component-type-helpers@3.3.0: + resolution: {integrity: sha512-vwR8DDsBysI9NWXa0okPFpCcW+BUC3sPTuLBNo1faMzw4QWMFd+3/lFYFu29ZN0q+8UReXWJHEYesC9dcXYCLg==} vue-docgen-api@4.79.2: resolution: {integrity: sha512-n9ENAcs+40awPZMsas7STqjkZiVlIjxIKgiJr5rSohDP0/JCrD9VtlzNojafsA1MChm/hz2h3PDtUedx3lbgfA==} @@ -19854,7 +19923,7 @@ snapshots: storybook: 10.4.0(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)(@testing-library/dom@10.4.1)(@types/react@19.2.14)(prettier@3.8.3)(react-dom@19.2.6)(react@19.2.6) type-fest: 2.19.0 vue: 3.5.34(typescript@5.9.3) - vue-component-type-helpers: 3.2.9 + vue-component-type-helpers: 3.3.0 '@stylexjs/babel-plugin@0.18.2': dependencies: @@ -21979,6 +22048,8 @@ snapshots: mimic-response: 3.1.0 optional: true + dedent-js@1.0.1: {} + dedent@0.7.0: {} dedent@1.7.0(babel-plugin-macros@3.1.0): @@ -27827,6 +27898,13 @@ snapshots: stylus: 0.64.0 typescript: 5.9.3 + svelte2tsx@0.7.55(svelte@5.55.7)(typescript@5.9.3): + dependencies: + dedent-js: 1.0.1 + scule: 1.3.0 + svelte: 5.55.7(@typescript-eslint/types@8.59.3) + typescript: 5.9.3 + svelte@5.55.7(@typescript-eslint/types@8.59.3): dependencies: '@jridgewell/remapping': 2.3.5 @@ -28663,7 +28741,7 @@ snapshots: vue-component-type-helpers@3.2.8: {} - vue-component-type-helpers@3.2.9: {} + vue-component-type-helpers@3.3.0: {} vue-docgen-api@4.79.2(vue@3.5.34): dependencies: diff --git a/rslib/svelte-basic/.gitignore b/rslib/svelte-basic/.gitignore new file mode 100644 index 00000000..14419eef --- /dev/null +++ b/rslib/svelte-basic/.gitignore @@ -0,0 +1,15 @@ +# Local +.DS_Store +*.local +*.log* + +# Dist +node_modules +dist/ +storybook-static +doc_build/ + +# IDE +.vscode/* +!.vscode/extensions.json +.idea diff --git a/rslib/svelte-basic/README.md b/rslib/svelte-basic/README.md new file mode 100644 index 00000000..1c03c8da --- /dev/null +++ b/rslib/svelte-basic/README.md @@ -0,0 +1,23 @@ +# Rslib project + +## Setup + +Install the dependencies: + +```bash +npm install +``` + +## Get started + +Build the library: + +```bash +npm run build +``` + +Build the library in watch mode: + +```bash +npm run dev +``` diff --git a/rslib/svelte-basic/package.json b/rslib/svelte-basic/package.json new file mode 100644 index 00000000..a5c8014b --- /dev/null +++ b/rslib/svelte-basic/package.json @@ -0,0 +1,35 @@ +{ + "name": "@rslib-example/svelte-basic", + "version": "0.0.0", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + }, + "./style.css": "./dist/index.css" + }, + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "rslib", + "check": "svelte-check --tsconfig ./tsconfig.json", + "dev": "rslib -w" + }, + "devDependencies": { + "@rsbuild/plugin-svelte": "^1.1.1", + "@rslib/core": "^0.21.5", + "@tsconfig/svelte": "^5.0.8", + "@types/node": "^24.12.4", + "svelte": "^5.55.5", + "svelte-check": "^4.4.8", + "svelte-preprocess": "^6.0.3", + "svelte2tsx": "^0.7.55", + "typescript": "^5.9.3" + }, + "peerDependencies": { + "svelte": "^5.0.0" + } +} diff --git a/rslib/svelte-basic/rslib.config.ts b/rslib/svelte-basic/rslib.config.ts new file mode 100644 index 00000000..86fb99de --- /dev/null +++ b/rslib/svelte-basic/rslib.config.ts @@ -0,0 +1,26 @@ +import { pluginSvelte } from '@rsbuild/plugin-svelte'; +import { defineConfig } from '@rslib/core'; +import { svelteDtsPlugin } from './scripts/rslib-plugin-svelte-dts'; + +export default defineConfig({ + resolve: { + conditionNames: ['svelte', 'browser', '...'], + }, + lib: [ + { + format: 'esm', + dts: false, + }, + ], + output: { + target: 'web', + }, + plugins: [ + pluginSvelte(), + svelteDtsPlugin({ + declarationDir: './dist', + libRoot: './src', + tsconfig: 'tsconfig.json', + }), + ], +}); diff --git a/rslib/svelte-basic/scripts/rslib-plugin-svelte-dts.ts b/rslib/svelte-basic/scripts/rslib-plugin-svelte-dts.ts new file mode 100644 index 00000000..a1a74c3d --- /dev/null +++ b/rslib/svelte-basic/scripts/rslib-plugin-svelte-dts.ts @@ -0,0 +1,49 @@ +import { createRequire } from 'node:module'; +import { resolve } from 'node:path'; +import type { RsbuildPlugin } from '@rslib/core'; +import { emitDts } from 'svelte2tsx'; + +const require = createRequire(import.meta.url); + +export interface SvelteDtsPluginOptions { + declarationDir?: string; + libRoot?: string; + tsconfig?: string; + svelteShimsPath?: string; +} + +const resolveProjectPath = (rootPath: string, path: string): string => resolve(rootPath, path); + +export function svelteDtsPlugin(options: SvelteDtsPluginOptions = {}): RsbuildPlugin { + return { + name: 'rslib-plugin-svelte-dts', + setup(api) { + api.onAfterBuild(async () => { + const { + declarationDir = './dist', + libRoot = './src', + tsconfig = 'tsconfig.json', + } = options; + + const rootPath = api.context.rootPath; + const svelteShimsPath = options.svelteShimsPath + ? resolveProjectPath(rootPath, options.svelteShimsPath) + : require.resolve('svelte2tsx/svelte-shims-v4.d.ts'); + + try { + await emitDts({ + declarationDir: resolveProjectPath(rootPath, declarationDir), + svelteShimsPath, + libRoot: resolveProjectPath(rootPath, libRoot), + tsconfig: resolveProjectPath(rootPath, tsconfig), + }); + + console.log('Svelte DTS generation complete'); + } catch (error) { + console.error('Svelte DTS generation failed:', error); + throw error; + } + }); + }, + }; +} diff --git a/rslib/svelte-basic/src/Button.svelte b/rslib/svelte-basic/src/Button.svelte new file mode 100644 index 00000000..8cc074c4 --- /dev/null +++ b/rslib/svelte-basic/src/Button.svelte @@ -0,0 +1,40 @@ + + + + + \ No newline at end of file diff --git a/rslib/svelte-basic/src/index.ts b/rslib/svelte-basic/src/index.ts new file mode 100644 index 00000000..ae34e39c --- /dev/null +++ b/rslib/svelte-basic/src/index.ts @@ -0,0 +1 @@ +export { default as Button } from './Button.svelte'; diff --git a/rslib/svelte-basic/svelte.config.ts b/rslib/svelte-basic/svelte.config.ts new file mode 100644 index 00000000..af7faa82 --- /dev/null +++ b/rslib/svelte-basic/svelte.config.ts @@ -0,0 +1,5 @@ +import { sveltePreprocess } from 'svelte-preprocess'; + +export default { + preprocess: sveltePreprocess(), +}; diff --git a/rslib/svelte-basic/tsconfig.json b/rslib/svelte-basic/tsconfig.json new file mode 100644 index 00000000..65784507 --- /dev/null +++ b/rslib/svelte-basic/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "@tsconfig/svelte/tsconfig.json", + "compilerOptions": { + "target": "ES2022", + "lib": ["DOM", "ES2022"], + "module": "preserve", + "moduleDetection": "force", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "types": ["node"], + "strict": true, + "declaration": true, + "emitDeclarationOnly": true, + "esModuleInterop": true, + "isolatedModules": true, + "verbatimModuleSyntax": true, + "skipLibCheck": true, + "noUnusedLocals": true + }, + "include": ["src", "scripts", "*.config.ts"] +} diff --git a/rslib/svelte-bundleless/.gitignore b/rslib/svelte-bundleless/.gitignore new file mode 100644 index 00000000..14419eef --- /dev/null +++ b/rslib/svelte-bundleless/.gitignore @@ -0,0 +1,15 @@ +# Local +.DS_Store +*.local +*.log* + +# Dist +node_modules +dist/ +storybook-static +doc_build/ + +# IDE +.vscode/* +!.vscode/extensions.json +.idea diff --git a/rslib/svelte-bundleless/README.md b/rslib/svelte-bundleless/README.md new file mode 100644 index 00000000..1c03c8da --- /dev/null +++ b/rslib/svelte-bundleless/README.md @@ -0,0 +1,23 @@ +# Rslib project + +## Setup + +Install the dependencies: + +```bash +npm install +``` + +## Get started + +Build the library: + +```bash +npm run build +``` + +Build the library in watch mode: + +```bash +npm run dev +``` diff --git a/rslib/svelte-bundleless/package.json b/rslib/svelte-bundleless/package.json new file mode 100644 index 00000000..b9ea21ea --- /dev/null +++ b/rslib/svelte-bundleless/package.json @@ -0,0 +1,35 @@ +{ + "name": "@rslib-example/svelte-bundleless", + "version": "0.0.0", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + }, + "./style.css": "./dist/index.css" + }, + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "rslib", + "check": "svelte-check --tsconfig ./tsconfig.json", + "dev": "rslib -w" + }, + "devDependencies": { + "@rsbuild/plugin-svelte": "^1.1.1", + "@rslib/core": "^0.21.5", + "@tsconfig/svelte": "^5.0.8", + "@types/node": "^24.12.4", + "svelte": "^5.55.5", + "svelte-check": "^4.4.8", + "svelte-preprocess": "^6.0.3", + "svelte2tsx": "^0.7.55", + "typescript": "^5.9.3" + }, + "peerDependencies": { + "svelte": "^5.0.0" + } +} diff --git a/rslib/svelte-bundleless/rslib.config.ts b/rslib/svelte-bundleless/rslib.config.ts new file mode 100644 index 00000000..a923a16c --- /dev/null +++ b/rslib/svelte-bundleless/rslib.config.ts @@ -0,0 +1,31 @@ +import { pluginSvelte } from '@rsbuild/plugin-svelte'; +import { defineConfig } from '@rslib/core'; +import { svelteDtsPlugin } from './scripts/rslib-plugin-svelte-dts'; + +export default defineConfig({ + resolve: { + conditionNames: ['svelte', 'browser', '...'], + }, + lib: [ + { + bundle: false, + format: 'esm', + dts: false, + }, + ], + output: { + target: 'web', + }, + plugins: [ + pluginSvelte({ + svelteLoaderOptions: { + emitCss: false, + }, + }), + svelteDtsPlugin({ + declarationDir: './dist', + libRoot: './src', + tsconfig: 'tsconfig.json', + }), + ], +}); diff --git a/rslib/svelte-bundleless/scripts/rslib-plugin-svelte-dts.ts b/rslib/svelte-bundleless/scripts/rslib-plugin-svelte-dts.ts new file mode 100644 index 00000000..a1a74c3d --- /dev/null +++ b/rslib/svelte-bundleless/scripts/rslib-plugin-svelte-dts.ts @@ -0,0 +1,49 @@ +import { createRequire } from 'node:module'; +import { resolve } from 'node:path'; +import type { RsbuildPlugin } from '@rslib/core'; +import { emitDts } from 'svelte2tsx'; + +const require = createRequire(import.meta.url); + +export interface SvelteDtsPluginOptions { + declarationDir?: string; + libRoot?: string; + tsconfig?: string; + svelteShimsPath?: string; +} + +const resolveProjectPath = (rootPath: string, path: string): string => resolve(rootPath, path); + +export function svelteDtsPlugin(options: SvelteDtsPluginOptions = {}): RsbuildPlugin { + return { + name: 'rslib-plugin-svelte-dts', + setup(api) { + api.onAfterBuild(async () => { + const { + declarationDir = './dist', + libRoot = './src', + tsconfig = 'tsconfig.json', + } = options; + + const rootPath = api.context.rootPath; + const svelteShimsPath = options.svelteShimsPath + ? resolveProjectPath(rootPath, options.svelteShimsPath) + : require.resolve('svelte2tsx/svelte-shims-v4.d.ts'); + + try { + await emitDts({ + declarationDir: resolveProjectPath(rootPath, declarationDir), + svelteShimsPath, + libRoot: resolveProjectPath(rootPath, libRoot), + tsconfig: resolveProjectPath(rootPath, tsconfig), + }); + + console.log('Svelte DTS generation complete'); + } catch (error) { + console.error('Svelte DTS generation failed:', error); + throw error; + } + }); + }, + }; +} diff --git a/rslib/svelte-bundleless/src/Button.svelte b/rslib/svelte-bundleless/src/Button.svelte new file mode 100644 index 00000000..8cc074c4 --- /dev/null +++ b/rslib/svelte-bundleless/src/Button.svelte @@ -0,0 +1,40 @@ + + + + + \ No newline at end of file diff --git a/rslib/svelte-bundleless/src/index.ts b/rslib/svelte-bundleless/src/index.ts new file mode 100644 index 00000000..ae34e39c --- /dev/null +++ b/rslib/svelte-bundleless/src/index.ts @@ -0,0 +1 @@ +export { default as Button } from './Button.svelte'; diff --git a/rslib/svelte-bundleless/svelte.config.ts b/rslib/svelte-bundleless/svelte.config.ts new file mode 100644 index 00000000..af7faa82 --- /dev/null +++ b/rslib/svelte-bundleless/svelte.config.ts @@ -0,0 +1,5 @@ +import { sveltePreprocess } from 'svelte-preprocess'; + +export default { + preprocess: sveltePreprocess(), +}; diff --git a/rslib/svelte-bundleless/tsconfig.json b/rslib/svelte-bundleless/tsconfig.json new file mode 100644 index 00000000..65784507 --- /dev/null +++ b/rslib/svelte-bundleless/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "@tsconfig/svelte/tsconfig.json", + "compilerOptions": { + "target": "ES2022", + "lib": ["DOM", "ES2022"], + "module": "preserve", + "moduleDetection": "force", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "types": ["node"], + "strict": true, + "declaration": true, + "emitDeclarationOnly": true, + "esModuleInterop": true, + "isolatedModules": true, + "verbatimModuleSyntax": true, + "skipLibCheck": true, + "noUnusedLocals": true + }, + "include": ["src", "scripts", "*.config.ts"] +}