A specialized build tool for creating Svelte component libraries and packages
—
Configuration loading and validation for Svelte projects with support for multiple config file formats.
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
});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}`);The system searches for configuration files in this order:
svelte.config.jssvelte.config.tsIf multiple files exist, the first one found is used and a warning is displayed.
config.package field// svelte.config.js
export default {
extensions: ['.svelte', '.svx'] // File extensions to process
};// 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'
}
};import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
// svelte.config.js
export default {
preprocess: vitePreprocess() // Svelte preprocessor
};The system will throw an error if the deprecated config.package field is found:
// This will cause an error
export default {
package: { // ❌ Deprecated
// ...
}
};If no configuration file is found, an empty configuration object is returned, allowing the system to use defaults.
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