CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sveltejs--package

A specialized build tool for creating Svelte component libraries and packages

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration Management

Configuration loading and validation for Svelte projects with support for multiple config file formats.

Capabilities

Load Config Function

Loads and validates Svelte configuration from svelte.config.js or svelte.config.ts files.

/**
 * Loads and validates Svelte config file
 * @param options - Configuration loading options
 * @returns Promise resolving to Svelte configuration
 */
function load_config(options?: { cwd?: string }): Promise<Config>;

interface Config {
  extensions?: string[];
  kit?: {
    alias?: Record<string, string>;
    files?: {
      lib?: string;
    };
    outDir?: string;
  };
  preprocess?: PreprocessorGroup;
}

Usage Examples:

import { load_config } from "@sveltejs/package/src/config.js";

// Load config from current directory
const config = await load_config();

// Load config from specific directory
const config = await load_config({ cwd: "/path/to/project" });

// Use config with build
import { build } from "@sveltejs/package/src/index.js";
await build({
  cwd: process.cwd(),
  input: config.kit?.files?.lib ?? "src/lib",
  output: "dist",
  preserve_output: false,
  types: true,
  config
});

Load Package JSON Function

Loads package.json file from the specified directory.

/**
 * Load package.json file
 * @param cwd - Directory to search for package.json (defaults to process.cwd())
 * @returns Parsed package.json object or empty object if not found
 */
function load_pkg_json(cwd?: string): Record<string, any>;

Usage Examples:

import { load_pkg_json } from "@sveltejs/package/src/config.js";

// Load package.json from current directory
const pkg = load_pkg_json();

// Load package.json from specific directory
const pkg = load_pkg_json("/path/to/project");

// Access package information
console.log(`Package name: ${pkg.name}`);
console.log(`Version: ${pkg.version}`);

Configuration File Discovery

Config File Resolution

The system searches for configuration files in this order:

  1. svelte.config.js
  2. svelte.config.ts

If multiple files exist, the first one found is used and a warning is displayed.

Configuration Loading Process

  1. Discovery: Search for config files in the specified directory
  2. Selection: Choose the first config file found
  3. Import: Dynamically import the config file with timestamp for cache busting
  4. Validation: Check for deprecated config.package field
  5. Return: Return the loaded configuration object

Configuration Structure

Extensions Configuration

// svelte.config.js
export default {
  extensions: ['.svelte', '.svx'] // File extensions to process
};

Kit Configuration

// svelte.config.js
export default {
  kit: {
    // Path aliases for import resolution
    alias: {
      '$lib': 'src/lib',
      '$utils': 'src/utils'
    },
    
    // File paths
    files: {
      lib: 'src/lib' // Library source directory
    },
    
    // Output directory for build artifacts
    outDir: '.svelte-kit'
  }
};

Preprocessing Configuration

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

// svelte.config.js
export default {
  preprocess: vitePreprocess() // Svelte preprocessor
};

Error Handling

Deprecated Configuration

The system will throw an error if the deprecated config.package field is found:

// This will cause an error
export default {
  package: { // ❌ Deprecated
    // ...
  }
};

Missing Configuration

If no configuration file is found, an empty configuration object is returned, allowing the system to use defaults.

Types

interface Config {
  extensions?: string[];
  kit?: {
    alias?: Record<string, string>;
    files?: {
      lib?: string;
    };
    outDir?: string;
  };
  preprocess?: PreprocessorGroup;
}

interface LoadConfigOptions {
  cwd?: string;
}

Install with Tessl CLI

npx tessl i tessl/npm-sveltejs--package

docs

build-system.md

configuration.md

filesystem.md

index.md

typescript.md

validation.md

tile.json