A webpack loader for Svelte components, allowing you to use Svelte with webpack. This version (3.2.4) supports Svelte 3, 4, and 5 (including runes mode). It handles Svelte files (.svelte) and with extra config supports TypeScript in Svelte files. Key differentiator: it's the official webpack integration from the Svelte team, maintained alongside SvelteKit and Vite plugin. Requires manual webpack configuration for CSS extraction, aliasing, and resolving conditions. Alternatives include vite-plugin-svelte for Vite users.
npm install svelte-loaderVerified import paths — ran on the pinned version, not inferred.
Setup webpack to bundle Svelte components with svelte-loader, including resolve aliasing and CSS extraction.
Add a rule: { test: /node_modules\/svelte\/.*\.mjs$/, resolve: { fullySpecified: false } }Use pattern: test: /\.svelte\.ts$/, use: ['svelte-loader', 'ts-loader']
Set resolve.alias: { svelte: path.resolve('node_modules', 'svelte/src/runtime') } for Svelte 3, or path.resolve('node_modules', 'svelte') for Svelte 4/5Add 'svelte' to both mainFields and conditionNames arrays in webpack config.
Set resolve.alias to point to a single Svelte installation as shown in the README.
Install svelte: npm install svelte --save-dev, and add alias in webpack config: alias: { svelte: path.resolve('node_modules', 'svelte') }Add a rule for .svelte files in webpack config: { test: /\.svelte$/, use: 'svelte-loader' }Add rule: { test: /node_modules\/svelte\/.*\.mjs$/, resolve: { fullySpecified: false } }For Svelte 5+ with TypeScript, use: { test: /\.svelte\.ts$/, use: ['svelte-loader', 'ts-loader'] }